• 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.

caller_env(n = 1)

current_env()

## Arguments

n Number of frames to go back.

caller_frame() and current_frame()

## Examples

# 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()#> $current #> <environment: 0x8788a08> #> #>$caller
#> <environment: 0x802a650>
#>
# Let's call fn() again but this time within a function:
g <- function() fn()

# Now the caller environment is also an unique execution environment.
# This is the exec env created by R for our call to g():
g()#> $current #> <environment: 0x83fbcf8> #> #>$caller
#> <environment: 0x83fbd68>
#>