If a frame or formula, the function will be retrieved from the associated environment. Otherwise, it is looked up in the calling frame.

call_fn(call, env = caller_env())

Arguments

call

Can be a call or a quosure that wraps a call.

env

The environment where to find the definition of the function quoted in call in case call is not wrapped in a quosure.

Life cycle

In rlang 0.2.0, lang_fn() was deprecated and renamed to call_fn(). See lifecycle section in call2() for more about this change.

See also

Examples

# Extract from a quoted call:
call_fn(quote(matrix()))
#> function (data = NA, nrow = 1, ncol = 1, byrow = FALSE, dimnames = NULL) 
#> {
#>     if (is.object(data) || !is.atomic(data)) 
#>         data <- as.vector(data)
#>     .Internal(matrix(data, nrow, ncol, byrow, dimnames, missing(nrow), 
#>         missing(ncol)))
#> }
#> <bytecode: 0x560ea929c3f8>
#> <environment: namespace:base>
call_fn(quo(matrix()))
#> function (data = NA, nrow = 1, ncol = 1, byrow = FALSE, dimnames = NULL) 
#> {
#>     if (is.object(data) || !is.atomic(data)) 
#>         data <- as.vector(data)
#>     .Internal(matrix(data, nrow, ncol, byrow, dimnames, missing(nrow), 
#>         missing(ncol)))
#> }
#> <bytecode: 0x560ea929c3f8>
#> <environment: namespace:base>

# Extract the calling function
test <- function() call_fn(call_frame())
test()
#> function() call_fn(call_frame())
#> <environment: 0x560eae363d18>