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

caller_env

Get the current or caller environment


Description

  • The current environment is the execution environment of the current function (the one currently being evaluated).

  • The caller environment is the execution environment of the function that called the current function.

Usage

caller_env(n = 1)

current_env()

Arguments

n

Number of frames to go back.

See Also

Examples

if (FALSE) {

# Let's create a function that returns its current environment and
# its caller environment:
fn <- function() list(current = current_env(), caller = caller_env())

# The current environment is an unique execution environment
# created when `fn()` was called. The caller environment is the
# global env because that's where we called `fn()`.
fn()

# Let's call `fn()` again but this time within a function:
g <- function() fn()

# Now the caller environment is also a unique execution environment.
# This is the exec env created by R for our call to g():
g()

}

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.