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_lazily(env = env_caller(), nm, expr, eval_env = NULL)env_assign_lazily_(env = env_caller(), nm, expr, eval_env = NULL)
- 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_lazily(), or a captured expression (either quoted or a formula) for the standard evaluation version
env_assign_lazily_(). 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_lazily()(or the underscore version) was called.
env <- env_new() env_assign_lazily(env, "name", cat("forced!\n")) env$name # Use the standard evaluation version with quoted expressions: f <- ~message("forced!") env_assign_lazily_(env, "name2", f) env$name2
Looks like there are no examples yet.