env_parent() returns the parent environment of env if called
with n = 1, the grandparent with n = 2, etc.
env_tail() searches through the parents and returns the one
which has empty_env() as parent.
env_parents() returns the list of all parents, including the
empty environment. This list is named using env_name().
See the section on inheritance in env()'s documentation.
env_parent(env = caller_env(), n = 1) env_tail(env = caller_env(), last = global_env(), sentinel = NULL) env_parents(env = caller_env(), last = global_env())
| env | An environment. |
|---|---|
| n | The number of generations to go up. |
| last | The environment at which to stop. Defaults to the global environment. The empty environment is always a stopping condition so it is safe to leave the default even when taking the tail or the parents of an environment on the search path.
|
| sentinel | This argument is defunct, please use |
An environment for env_parent() and env_tail(), a list
of environments for env_parents().
The sentinel argument of env_tail() has been deprecated in
rlang 0.2.0 and renamed to last. It is defunct as of rlang 0.4.0.
#> <environment: package:rlang> #> attr(,"name") #> [1] "package:rlang" #> attr(,"path") #> [1] "/data/deployment/2020-03-30/renv/library/R-3.6/x86_64-pc-linux-gnu/rlang"#> <environment: base># By default, env_parent() returns the parent environment of the # current evaluation frame. If called at top-level (the global # frame), the following two expressions are equivalent: env_parent()#> <environment: 0x555f440dfc38>env_parent(base_env())#> <environment: R_EmptyEnv># This default is more handy when called within a function. In this # case, the enclosure environment of the function is returned # (since it is the parent of the evaluation frame): enclos_env <- env() fn <- set_env(function() env_parent(), enclos_env) identical(enclos_env, fn())#> [1] TRUE