is_callable

0th

Percentile

Is an object callable?

A callable object is an object that can be set as the head of a call node. This includes symbolic objects that evaluate to a function or literal functions.

Usage
is_callable(x)
Arguments
x

An object to test.

Details

Note that strings may look like callable objects because expressions of the form "list"() are valid R code. However, that's only because the R parser transforms strings to symbols. It is not legal to manually set language heads to strings.

Aliases
  • is_callable
Examples
# NOT RUN {
# Symbolic objects and functions are callable:
is_callable(quote(foo))
is_callable(base::identity)

# mut_node_car() lets you modify calls without any checking:
lang <- quote(foo(10))
mut_node_car(lang, get_env())

# Use is_callable() to check an input object is safe to put as CAR:
obj <- base::identity

if (is_callable(obj)) {
  lang <- mut_node_car(lang, obj)
} else {
  abort("`obj` must be callable")
}

eval_bare(lang)
# }
Documentation reproduced from package rlang, version 0.1.6, License: GPL-3

Community examples

Looks like there are no examples yet.