env_set

0th

Percentile

Set an environment.

env_set() does not work by side effect. The input is copied before being assigned an environment, and left unchanged. However, env_set_parent() operates on the inner environment and does have a side effect.

Usage
env_set(env, new_env)
"env_set"(env, new_env)
"env_set"(env, new_env)
"env_set"(env, new_env)
env_set_parent(env, new_env)
Arguments
env
An environment or an object with a S3 method for env_set().
new_env
An environment to replace env with. Can be an object with an S method for env().
Aliases
  • env_set
  • env_set.function
  • env_set.formula
  • env_set.environment
  • env_set_parent
Examples
# Create a function with a given environment:
env <- new_env(base_env())
fn <- with_env(env, function() NULL)
identical(env(fn), env)

# env_set() does not work by side effect. Setting a new environment
# for fn has no effect on the original function:
other_env <- new_env()
env_set(fn, other_env)
identical(env(fn), other_env)

# env_set() returns a new function with a different environment, so
# you need to assign the returned function to the `fn` name:
fn <- env_set(fn, other_env)
identical(env(fn), other_env)
Documentation reproduced from package rlang, version 0.0.0.9000, License: GPL-3

Community examples

Looks like there are no examples yet.