Based on a JSON schema, ajv is used to create a validator
object in Javascript that can be used to check a configuration.
This is done in a QuickJS context (QuickJSR::JSContext), and stored inside
the context property of the the object.
All YAML is parsed in R, so the validated data is what R reads:
Files are read with
yaml::read_yaml().S7schemaobjects are converted withto_yaml()and read back withyaml::yaml.load(), so the validated data matches whatwrite_config()writes.listobjects invalidate_list()are validated as they are.
The resulting list is converted to JSON with jsonlite::toJSON() and
validated by ajv. The JavaScript side never parses YAML.
NA, NaN, and Inf values become null in the JSON sent to ajv.
Numbers are sent with 17 significant digits, so numbers from files and
lists are validated exactly. S7schema objects are validated as
write_config() writes them, so numbers that need 17 significant digits
(e.g. 0.1 + 0.2) are rounded.
See json-schema.org on how to specify a JSON schema.
Usage
validator(schema, call = rlang::caller_env())Arguments
- schema
character(1)path to a JSON schema.- call
The execution environment shown in error messages if the schema is invalid. See
rlang::abort().
Properties
- context
QuickJSR::JSContext with a validator object based on the schema
