List-like Environment of Functions (and More)
funEnv.RdConstruct a “list”, really an environment
typically of functions and optionally other R objects, where the
functions and formulas all
all share the same environment.
Consequently, the functions may call each other.
On technical level, this is just a simple wrapper around
list2env().
Usage
funEnv(..., envir = NULL, parent = parent.frame(),
hash = (...length() > 100), size = max(29L, ...length()))Arguments
- ...
an arbitrary named “list” of R objects, typically including several
functions.- envir
an
environmentorNULL.- parent
(for the case
envir = NULL): a parent frame aka enclosing environment, seenew.envandlist2env.- hash, size
(for the case
envir = NULL):hasha logical indicating if the created environment should use hashing, and (size) the hash size, seelist2env.
Value
an environment, say E, containing the objects
from ... (plus those in envir), and all function
objects' environment() is E.
Examples
ee <- funEnv(f = function(x) g(2*(x+1)),
g = function(y) hh(y+1),
hh = function(u) u^2,
info = "Some Information (not a function)")
ls(ee) # here the same as names(ee)
#> [1] "f" "g" "hh" "info"
## Check that it works: i.e., that "f sees g" and "g sees hh":
stopifnot(all.equal(ee$f(pi), (2*pi+3)^2))
ee$f(0:4) # [1] 9 25 49 81 121
#> [1] 9 25 49 81 121