scoped_bindings {rlang}R Documentation

Temporarily change bindings of an environment

Description

Usage

scoped_bindings(..., .env = .frame, .frame = caller_env())

with_bindings(.expr, ..., .env = caller_env())

Arguments

...

Pairs of names and values. These dots support splicing (with value semantics) and name unquoting.

.env

An environment or an object bundling an environment, e.g. a formula, quosure or closure. This argument is passed to get_env().

.frame

The frame environment that determines the scope of the temporary bindings. When that frame is popped from the call stack, bindings are switched back to their original values.

.expr

An expression to evaluate with temporary bindings.

Value

scoped_bindings() returns the values of old bindings invisibly; with_bindings() returns the value of expr.

Examples

foo <- "foo"
bar <- "bar"

# `foo` will be temporarily rebinded while executing `expr`
with_bindings(paste(foo, bar), foo = "rebinded")
paste(foo, bar)

[Package rlang version 0.2.2 Index]