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

lang_fn(lang)

Arguments

lang

Can be a call (language object), a formula quoting a call in the right-hand side, or a frame object from which to extract the call expression.

See also

lang_name()

Examples

# Extract from a quoted call: lang_fn(~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: 0x7f979b39b580> #> <environment: namespace:base>
lang_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: 0x7f979b39b580> #> <environment: namespace:base>
# Extract the calling function test <- function() lang_fn(call_frame()) test()
#> function() lang_fn(call_frame()) #> <environment: 0x7f97a420df88>