env_assign

0th

Percentile

Assign objects to an environment.

These functions create bindings in the specified environment. The bindings are supplied as pairs of names and values, either directly (env_assign()), in dots (env_define()), or from a dictionary (env_bind()). See is_dictionary() for the definition of a dictionary.

Usage
env_assign(env = caller_env(), nm, x)
env_bind(env = caller_env(), data = list())
env_define(env = caller_env(), ...)
Arguments
env
An environment or an object with a S3 method for env(). If missing, the environment of the current evaluation frame is returned.
nm
The name of the binding.
x
The value of the binding.
data
A vector with unique names which defines bindings (pairs of name and value). See is_dictionary().
...
Pairs of unique names and R objects used to define new bindings.
Details

These functions operate by side effect. For example, if you assign bindings to a closure function, the environment of the function is modified in place.

Value

The input object env, with its associated environment modified in place.

Aliases
  • env_assign
  • env_bind
  • env_define
Examples
# Create a function that uses undefined bindings:
fn <- function() list(a, b, c, d, e)
env(fn) <- new_env(base_env())

# This would throw a scoping error if run:
# fn()

data <- stats::setNames(letters, letters)
env_bind(fn, data)

# fn() now sees the objects
fn()

# Redefine new bindings:
fn <- env_assign(fn, "a", "1")
fn <- env_define(fn, b = "2", c = "3")
fn()
Documentation reproduced from package rlang, version 0.0.0.9000, License: GPL-3

Community examples

Looks like there are no examples yet.