Creates a callable validation object that accumulates checks via the base
pipe operator |>. The resulting object behaves like a function: call it
with a value to validate.
Calling convention
Validators accept value as the first argument, plus context via named
arguments in ... or as a named list in .ctx:
Named arguments in ... take precedence over .ctx entries with the
same name. If a step declares dependencies (e.g. require_length_matches(~ nrow(newdata))), the validator checks that all required context is present
before running any steps and errors early if not.
See also
Other core:
as_contract_block(),
as_contract_text(),
fail(),
require_custom()
Examples
# Define a validator
require_positive <- restrict("x") |>
require_numeric(no_na = TRUE) |>
require_between(lower = 0, exclusive_lower = TRUE)
# Use it
require_positive(5) # passes silently
# Compose with pipe
require_score <- restrict("score") |>
require_numeric() |>
require_length(1L) |>
require_between(lower = 0, upper = 100)