checkmate (version 1.7.2)

makeExpectation: Turn a Check into an Expectation

Description

makeExpectation is the internal function used to evaluate the result of a check and turn it into an expectation. makeExceptionFunction can be used to automatically create an expectation function based on a check function (see example).

Usage

makeExpectation(x, res, info = NULL, label = NULL)

makeExpectationFunction(check.fun, c.fun = NULL, env = parent.frame())

Arguments

x
[any] Object to check.
res
[TRUE | character(1)] The result of a check function: TRUE for successful checks, and an error message as string otherwise.
info
[character(1)] See expect_that
label
[character(1)] See expect_that
check.fun
[function] Function which checks the input. Must return TRUE on success and a string with the error message otherwise.
c.fun
[character(1)] If not NULL, instead of calling the function check.fun, use .Call to call a C function c.fun with the identical set of parameters. The C function must be registered as a n
env
[environment] The environment of the created function. Default is the parent.frame.

Value

  • makeExpectation returns the expectation result. makeExpectationFunction returns a function.

Examples

Run this code
# Simple custom check function
checkFalse = function(x) if (!identical(x, FALSE)) "Must be FALSE" else TRUE

# Create the respective expect function
expect_false = function(x, info = NULL, label = NULL) {
  res = checkFalse(x)
  makeExpectation(res, info = info, label = label)
}

# Alternative: Automatically create such a function
expect_false = makeExpectationFunction(checkFalse)
print(expect_false)

Run the code above in your browser using DataLab