env_assign_promise

0th

Percentile

Assign a promise to an environment.

These functions let you create a promise in an environment. Such promises behave just like lazily evaluated arguments. They are evaluated whenever they are touched by code, but not when they are passed as arguments.

Usage
env_assign_promise(env = caller_env(), nm, expr, eval_env = caller_env())
env_assign_promise_(env = caller_env(), nm, expr, eval_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.
expr
An expression to capture for env_assign_promise(), or a captured expression (either quoted or a formula) for the standard evaluation version env_assign_promise_(). This expression is used to create a promise in env.
eval_env
The environment where the promise will be evaluated when the promise gets forced. If expr is a formula, its environment is used instead. If not a formula and eval_env is not supplied, the promise is evaluated in the environment where env_assign_promise() (or the underscore version) was called.
See Also

env_assign()

Aliases
  • env_assign_promise
  • env_assign_promise_
Examples
env <- new_env()
env_assign_promise(env, "name", cat("forced!\n"))
env$name

# Use the standard evaluation version with quoted expressions:
f <- ~message("forced!")
env_assign_promise_(env, "name2", f)
env$name2
Documentation reproduced from package rlang, version 0.0.0.9000, License: GPL-3

Community examples

Looks like there are no examples yet.