restrict_fn_env | R Documentation |
Build a new function with an optimal scope. Normally the entire
environment tree (including the entire ancestry) is kept in memory as long
as a function is present. This is a common cause for memory leaks.
With restrict_fn_env()
you create a function that has only
the needed variables (copies) in the scope and the optimal scope ancestry can
be defined by argument parent_env
.
Be sure, to choose the right environment for parent_env
!
restrict_fn_env(
fn,
vars = NULL,
lookup_env = environment(fn),
parent_env = .GlobalEnv
)
fn |
A function whose parent scope should be restricted to the
set of variables given in |
vars |
An optional object, telling which variables should be
available in
|
lookup_env |
The environment holding the variables for which the names
are defined in the character vector |
parent_env |
The parent environment, which should be assigned to
the restricted function. This argument is very important, since it
determines which objects will be available inside of your function.
Usually one of the following two possibilities is the right choice for
|
A new function with a small scope containing the variables given
in vars
.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.