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

Description Usage Arguments Value References See Also Examples

View source: R/is-function.R

Description

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

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# 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")
})

assertive.types documentation built on May 1, 2019, 10:31 p.m.