conserve
allows its third argument to be bound to the name given as its
second argument in the local environment, while returning the first argument.
A sort of side-effect function which binds to the caller environment.
Arguments
- obj
[R
object
] Any object, specifically data.- name
[
symbol
orstring
] The name to which a value is to be bound locally.- value
[R
object
] The value for the name.
Conserving Intermediate Objects
The best use of conserve
is when one needs to keep an object in a long
sequence of commands to be used later in the same sequence (so mostly pipes).
It is essential to provide this local context (e.g. using local
or inside
functions) and avoid altering the global environment, since internally,
rlang::local_bindings
is used. The conserve
function is what is used with
the "convey" pipe to bind intermediary objects to provided symbols. Exported
for the rare occasion it may be useful on its own. One can also specifically
set conserve(name, value)
directives among the convey
instructions.
The value
argument can be specified in as a magrittr
pipe context. That
is, automatic data masking as well as the .
symbol representing the
original object.