Check if a configuration is in accordance with a JSON schema definition.
It is possible to either validate an existing list object in memory or an existing
yaml configuration file.
Details
The content is validated as R reads it: files are read with
yaml::read_yaml(), and S7schema objects are converted with to_yaml()
and read back before validation. list objects in validate_list() are
validated as they are.
See internal validator() documentation for more info on how the validation is done.
In YAML files and S7schema objects, R reads a YAML sequence with one item
([a]) as a single value ("a"). For fields that can hold one or more
values, allow both forms in the schema with oneOf:
NA, NaN, and Inf values are validated as null. A field that may be
missing must allow null in the schema:
Numbers with up to 16 significant digits are validated exactly. Numbers that
need 17, e.g. 0.1 + 0.2, are validated exactly in files and lists, but
rounded in S7schema objects, as to_yaml() writes them.
Examples
# Validate list object in memory
validate_list(
x = list(my_config_var = 1),
schema = system.file("examples/schema.json", package = "S7schema")
) |>
print()
#> $my_config_var
#> [1] 1
#>
# Validate yaml file on disk
validate_yaml(
file = system.file("examples/config.yml", package = "S7schema"),
schema = system.file("examples/schema.json", package = "S7schema")
) |>
print()
#> [1] "/home/runner/work/_temp/Library/S7schema/examples/config.yml"
