Substitute values into expression, thereby simplifying the rule set. Rules that evaluate to TRUE because of the substitution are removed.

substitute_values(.x, .values = list(...), ..., .add_constraints = TRUE)

Arguments

.x

validator object with rules

.values

(optional) named list with values for variables to substitute

...

alternative way of supplying values for variables (see examples).

.add_constraints

logical, should values be added as constraints to the resulting validator object?

Examples

library(validate)
rules <- validator( rule1 = z > 1
                  , rule2 = y > z
                  )
# rule1 is dropped, since it always is true
substitute_values(rules, list(z=2))
#> Object of class 'validator' with 2 elements:
#>  rule2   : y > 2
#>  .const_z: z == 2

# you can also supply the values as separate parameters
substitute_values(rules, z = 2)
#> Object of class 'validator' with 2 elements:
#>  rule2   : y > 2
#>  .const_z: z == 2

# you can choose to not add substituted values as a constraint
substitute_values(rules, z = 2, .add_constraints = FALSE)
#> Object of class 'validator' with 1 elements:
#>  rule2: y > 2

rules <- validator( rule1 = if (gender == "male") age >= 18 )
substitute_values(rules, gender="male")
#> Object of class 'validator' with 2 elements:
#>  rule1        : age >= 18
#>  .const_gender: gender == "male"
substitute_values(rules, gender="female")
#> Object of class 'validator' with 1 elements:
#>  .const_gender: gender == "female"