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()
)

Arguments

func

A function whose first argument takes a vector to check, and returns a logical vector of the same length with the results.

func_desc

A character function description to use in the expectation failure message.

vars

Included for backwards compatibility only.

all

Function to use to combine results for each vector.

env

The parent environment of the function, defaults to the calling environment of expect_make().

Value

An expect_*() style function.

Examples

# 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"