eval_closure | R Documentation |
Evaluate an expression inside of closure that has an optimal scope.
This is very important, if your closure does return a function, since the
the entire environment tree (including the entire ancestry) is kept
in memory as long as your function is present. This is a common cause for
memory leaks.
With eval_closure()
you can assign an environment that contains only
the needed variables (copies) and an optimal scope ancestry can be defined by
parent_env
. Be sure, to choose the right environment for parent_env
!
eval_closure(
expr,
vars = NULL,
lookup_env = parent.frame(),
parent_env = .GlobalEnv
)
expr |
The expression, which should be evaluated inside of the closure. |
vars |
An optional object, telling which variables should be available inside the closure. It can either be
|
lookup_env |
The environment holding the variables for which the names
are defined in the character vector |
parent_env |
The parent environment (either an environment or a string
holding the name of an R package whoose namespace should be used as parent
environment), which should be assigned to
the closure. This argument is very important, since it
determines which objects will be available inside of your closure.
Usually one of the following two possibilities is the right choice for
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.