expect_make()
creates an expectation from a vectorised checking function to
allow simple generation of domain specific data checks.
expect_make(
func,
func_desc = NULL,
vars = FALSE,
all = TRUE,
env = caller_env()
)
A function whose first argument takes a vector to check, and returns a logical vector of the same length with the results.
A character function description to use in the expectation failure message.
Included for backwards compatibility only.
Function to use to combine results for each vector.
The parent environment of the function, defaults to the calling
environment of expect_make()
.
An expect_*()
style function.
# Create a custom check
chk_binary <- function(x) {
suppressWarnings(as.integer(x) %in% 0:1)
}
# Create custom expectation function
expect_binary <- expect_make(chk_binary)
#> Error: object 'chk_binary' not found
# Validate a data frame
try(expect_binary(vs, data = mtcars))
#> Error in expect_binary(vs, data = mtcars) :
#> could not find function "expect_binary"
try(expect_binary(cyl, data = mtcars))
#> Error in expect_binary(cyl, data = mtcars) :
#> could not find function "expect_binary"