Skip to contents

EXPERIMENTAL Minimalistic mutli-criteria data validation. Designed to work nicely together with assert_all() (see examples)

Usage

validate(..., .all = TRUE)

Arguments

...

Arbitrary expressions that evaluate to either TRUE or FALSE. Expressions that evaluate to anything else, will be counted as FALSE and throw a warning. You can name the expressions to generate nice labels (but that's usually not necessary).

.all

logical scalar. Wrap each expression in ... in all() (useful for validating columns in data.frames)

Value

a named logical vector that is guranteed to have no NAs.

Examples

validation <- validate(
  all(iris$Petal.Length < 5),
  `all species are valid` = all(iris$Species %in% c("setosa", "versicolor", "virginica")),
  `all sepals are small` = all(iris$Sepal.Length < 1)
)

# validate can be used `with()` for added convenience:
validation <- with(iris, validate(
  all(Petal.Length < 5),
  `all species are valid` = all(Species %in% c("setosa", "versicolor", "virginica")),
  `all sepals are small` = all(Sepal.Length < 1)
))

# validate works together with assert_all to produce nice errors
try(
  assert_all(validation)
)
#> Error in try(assert_all(validation)) : Assertion failed
#> [1] `all(Petal.Length < 5)` is not TRUE
#> [3] `all sepals are small` is not TRUE