assertive.types (version 0.0-3)

assert_is_closure_function: Is the input a closure, builtin or special function?

Description

Checks to see if the input is a closure, builtin or special function.

Usage

assert_is_closure_function(x, severity = getOption("assertive.severity", "stop"))
assert_is_builtin_function(x, severity = getOption("assertive.severity", "stop"))
assert_is_special_function(x, severity = getOption("assertive.severity", "stop"))
is_closure_function(x, .xname = get_name_in_parent(x))
is_builtin_function(x, .xname = get_name_in_parent(x))
is_special_function(x, .xname = get_name_in_parent(x))

Arguments

x
Input to check.
severity
How severe should the consequences of the assertion be? Either "stop", "warning", "message", or "none".
.xname
Not intended to be used directly.

Value

is_internal_function returns TRUE when the input is a closure function that calls .Internal. The assert_* function returns nothing but throw an error if the corresponding is_* function returns FALSE.

References

There is some discussion of closure vs. builtin vs. special functions in the Argument Evaluation section of R-internals. https://cran.r-project.org/doc/manuals/r-devel/R-ints.html#Argument-evaluation

See Also

is.function and its assertive wrapper is_function. typeof is used to distinguish the three types of function.

Examples

Run this code
# most functions are closures
is_closure_function(mean)
is_closure_function(lm)
is_closure_function(summary)

# builtin functions are typically math operators, low level math functions
# and commonly used functions
is_builtin_function(`*`)
is_builtin_function(cumsum)
is_builtin_function(is.numeric)

# special functions are mostly language features 
is_special_function(`if`)
is_special_function(`return`)
is_special_function(`~`)

# some failure messages
assertive.base::dont_stop({
assert_is_builtin_function(mean)
assert_is_builtin_function("mean")
})

Run the code above in your browser using DataLab