Description Usage Arguments Details Value Note See Also Examples
Create and set an environment where elements (e.g. functions) within a non-nested named list of functions see each other. This function is normally used within other functions.
1 | addtoenv(L, p = parent.frame())
|
L |
a non-nested list of named functions. |
p |
the environment where the functions are assigned to. Defaults to the parent frame. |
This function is used by the ‘solver functions’ of simecol
.
The list of functions within a common environment.
This is a very special function that uses environment manipulations. Its main purpose is to ‘open’ the access to interdependend functions within a common list structure (function list).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | eq <- list(f1 = function(x, y) x + y,
f2 = function(a, x, y) a * f1(x, y)
)
fx <- function(eq) {
eq <- addtoenv(eq)
print(ls())
print(environment(eq$f1))
f1(3,4) + f2(1,2,3)
}
fx(eq)
## eq$f2(2,3,4) # should give an error outside fx
environment(eq$f2) # should return R_GlobalEnv again
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.