Learn R Programming

checkmate (version 1.6.2)

checkFunction: Check if an argument is a function

Description

Check if an argument is a function

Usage

checkFunction(x, args = NULL, ordered = FALSE, nargs = NULL)

assertFunction(x, args = NULL, ordered = FALSE, nargs = NULL, .var.name)

testFunction(x, args = NULL, ordered = FALSE, nargs = NULL)

expect_function(x, args = NULL, ordered = FALSE, nargs = NULL, info = NULL, label = NULL)

Arguments

x
[any] Object to check.
args
[character] Expected formal arguments. Checks that a function has no arguments if set to character(0). Default is NULL (no check).
ordered
[logical(1)] Flag whether the arguments provided in args must be the first length(args) arguments of the function in the specified order. Default is FALSE.
nargs
[integer(1)] Required number of arguments, without .... Default is NULL (no check).
.var.name
[character(1)] Name for x. Defaults to a heuristic to determine the name using deparse and substitute.
info
[character(1)] Extra information to be included in the message for the testthat reporter. See expect_that.
label
[character(1)] Same as .var.name, but passed down to expect_that.

Value

  • Depending on the function prefix: If the check is successful, all functions return TRUE. If the check is not successful, assertFunction throws an error message, testFunction returns FALSE, checkFunction returns a string with the error message. The function expect_function will return an expectation.

See Also

Other basetypes: assertArray, checkArray, expect_array, testArray; assertAtomicVector, checkAtomicVector, expect_atomic_vector, testAtomicVector; assertAtomic, checkAtomic, expect_atomic, testAtomic; assertCharacter, checkCharacter, expect_character, testCharacter; assertComplex, checkComplex, expect_complex, testComplex; assertDataFrame, checkDataFrame, expect_data_frame, testDataFrame; assertEnvironment, checkEnvironment, expect_environment, testEnvironment; assertFactor, checkFactor, expect_factor, testFactor; assertIntegerish, checkIntegerish, expect_integerish, testIntegerish; assertInteger, checkInteger, expect_integer, testInteger; assertList, checkList, expect_list, testList; assertLogical, checkLogical, expect_logical, testLogical; assertMatrix, checkMatrix, expect_matrix, testMatrix; assertNumeric, checkNumeric, expect_numeric, testNumeric; assertVector, checkVector, expect_vector, testVector

Examples

Run this code
testFunction(mean)
testFunction(mean, args = "x")

Run the code above in your browser using DataLab