Simple data validation
validate.Rd
EXPERIMENTAL Minimalistic mutli-criteria data validation. Designed to
work nicely together with assert_all()
(see examples)
Arguments
- ...
Arbitrary expressions that evaluate to either
TRUE
orFALSE
. Expressions that evaluate to anything else, will be counted asFALSE
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...
inall()
(useful for validating columns indata.frames
)
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