Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

is_callable

Is an object callable?


Description

A callable object is an object that can appear in the function position of a call (as opposed to argument position). This includes symbolic objects that evaluate to a function or literal functions embedded in the call.

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.

Examples

# Symbolic objects and functions are callable:
is_callable(quote(foo))
is_callable(base::identity)

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

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

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

eval_bare(lang)

rlang

Functions for Base Types and Core R and 'Tidyverse' Features

v0.4.11
MIT + file LICENSE
Authors
Lionel Henry [aut, cre], Hadley Wickham [aut], mikefc [cph] (Hash implementation based on Mike's xxhashlite), Yann Collet [cph] (Author of the embedded xxHash library), RStudio [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.