Passes when the value satisfies at least one of the alternative validators. When none passes, the error lists the first failure of every alternative.
Arguments
- restriction
a
restrictionobject.- ...
restrictionobjects, the alternatives.- .label
optional character(1) description for
print()and contract text; defaults to the alternatives' own labels.
Details
Each alternative runs in fail-first mode. Context needed by any
alternative is required from the caller, like for any other step. Missing
context is a usage error, not an alternative failing. In .on_fail = "all" mode the step reports a single failure.
See also
Other composition:
allow_null(),
require_col(),
require_each(),
require_fields(),
require_valid()
Examples
num_or_df <- restrict("x") |>
require_any(
restrict("x") |> require_numeric(),
restrict("x") |> require_df() |> require_has_cols("value")
)
num_or_df(1:3)
num_or_df(data.frame(value = 1))
try(num_or_df("a"))
#> Error : x: must satisfy one of:
#> - must be numeric, got character
#> - must be a data.frame, got character