Learn R Programming

toscutil (version 2.8.0)

function_locals: Get Function Environment as List

Description

Returns the function environment as list. Raises an error when called outside a function. By default, objects specified as arguments are removed from the environment.

Usage

function_locals(without = c(), strip_function_args = TRUE)

Value

The function environment as list

Arguments

without

character vector of symbols to exclude

strip_function_args

Whether to exclude symbols with the same name as the function arguments

Details

The order of the symbols in the returned list is arbitrary.

Examples

Run this code
f <- function(a = 1, b = 2) {
    x <- 3
    y <- 4
    return(function_locals())
}
all.equal(setdiff(f(), list(x = 3, y = 4)), list())

Run the code above in your browser using DataLab