Non-throwing predicate: returns TRUE when value passes every step of
validator, FALSE otherwise. Use it to branch on validity instead of
wrapping a validator call in tryCatch().
Arguments
- validator
a
restrictionobject created byrestrict().- value
the value to validate.
- ...
context arguments passed to the validator (e.g.
newdata = df), the same as a direct validator call.
Details
Like validation_errors(), only validation failures are caught;
a missing context dependency still raises so a calling mistake is not
mistaken for invalid data.
See also
validation_errors() for the failure messages.
Other core:
as_contract_block(),
as_contract_text(),
fail(),
require_custom(),
restrict(),
validation_errors()
Examples
v <- restrict("x") |> require_numeric(no_na = TRUE)
is_valid(v, 1:5) # TRUE
#> [1] TRUE
is_valid(v, c(1, NA)) # FALSE
#> [1] FALSE