Applies a different validator to each named element of a list, for
heterogeneous configuration or argument lists. Errors carry the field path,
e.g. opts$alpha.
Arguments
- restriction
a
restrictionobject.- ...
named
restrictionobjects, one per field.- .required
logical; if
TRUE(default) a missing field is a failure. IfFALSE, a missing field passes. A field whose validator allowsNULL(seeallow_null()) may always be missing.
See also
Other composition:
allow_null(),
require_any(),
require_col(),
require_each(),
require_valid()
Examples
opts_v <- restrict("opts") |>
require_class("list") |>
require_fields(
alpha = restrict("alpha") |> require_numeric() |> require_between(0, 1),
label = restrict("label") |> require_character()
)
opts_v(list(alpha = 0.05, label = "a"))
validation_errors(opts_v, list(alpha = 2))
#> [1] "opts$alpha: must be in [0, 1]\n Found: 2"
#> [2] "opts$label: is required but missing"