Skip to contents

r8validate(x) checks an R8 value against its own type again, rules included: a value built by its constructor is valid, and one that other code changed in place may not be. With against, any object is held against a type or rules. What does not satisfy them is an error; r8check() reports it instead.

Usage

r8validate(x, against = NULL, complete = FALSE)

Arguments

x

An R8 value, or, with against, any object.

against

Optional: A field type, such as type_table(...) or vec(type_double()), an R8 type object, a rule(), or a list of rules.

complete

Logical: Require every context and computed field of an R8 value to be present.

Value

x, invisibly; raises r8_value_error with the problems.

Examples

op <- options(r8.namespace = "demo")
Fit <- new_struct("FitSettings", fields = list(
  mtry = field(option(type_integer(min = 1L)), context = TRUE)
))
r8validate(Fit())
try(r8validate(Fit(), complete = TRUE))
#> Error : `demo::FitSettings` has pending fields: `mtry` (context). r8resolve() fills them.
try(r8validate(c(1, -1), vec(type_double(min = 0))))
#> Error : Invalid `x`: 1 problem
#> - `x[[2]]` must be at least 0; found -1. [below_min]
try(r8validate(data.frame(lo = 2, hi = 1), rule(lo <= hi)))
#> Error : Invalid `x`: The rule does not hold on 1 row
#>   rule 1  1 row fails (row 1)
#>   $problems lists 1 problem
options(op)