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.
env_assign_promise(env = caller_env(), nm, expr, eval_env = caller_env())env_assign_promise_(env = caller_env(), nm, expr, eval_env = caller_env())
- An environment or an object with a S3 method for
env(). If missing, the environment of the current evaluation frame is returned.
- The name of the binding.
- 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
- The environment where the promise will be evaluated
when the promise gets forced. If
expris a formula, its environment is used instead. If not a formula and
eval_envis not supplied, the promise is evaluated in the environment where
env_assign_promise()(or the underscore version) was called.
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
Looks like there are no examples yet.