expect_make {testdat}R Documentation

Create an expectation from a check function

Description

expect_make() creates an expectation from a vectorised checking function to allow simple generation of domain specific data checks.

Usage

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)

# Validate a data frame
try(expect_binary(vs, data = mtcars))
try(expect_binary(cyl, data = mtcars))


[Package testdat version 0.4.2 Index]