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

env_bury

Mask bindings by defining symbols deeper in a scope


Description

Superseded lifecycle

This function is superseded. Please use env() (and possibly set_env() if you're masking the bindings for another object like a closure or a formula) instead.

env_bury() is like env_bind() but it creates the bindings in a new child environment. This makes sure the new bindings have precedence over old ones, without altering existing environments. Unlike env_bind(), this function does not have side effects and returns a new environment (or object wrapping that environment).

Usage

env_bury(.env, ...)

Arguments

.env

An environment.

...

<dynamic> Named objects (env_bind()), expressions env_bind_lazy(), or functions (env_bind_active()). Use zap() to remove bindings.

Value

A copy of .env enclosing the new environment containing bindings to ... arguments.

See Also

Examples

orig_env <- env(a = 10)
fn <- set_env(function() a, orig_env)

# fn() currently sees `a` as the value `10`:
fn()

# env_bury() will bury the current scope of fn() behind a new
# environment:
fn <- env_bury(fn, a = 1000)
fn()

# Even though the symbol `a` is still defined deeper in the scope:
orig_env$a

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.