Displaying 1 result from an estimated 1 matches for "addtoenv".
2008 Jan 21
2
experiments with slot functions and possible problems NOTE
...etc
## 2) Now we try to construct closures
## 2a) non-nested
makefun1 <- function(flist) {
with(flist,
function() foo()
)
}
## 2b) nested call
makefun2 <- function(flist) {
with(flist,
function() bar()
)
}
## 2c) or use an alternative way with a special function
## addtoenv, suggested by Gabor Grothendieck some times ago:
addtoenv <- function(L, p = parent.frame()) {
for(nm in names(L)) {
assign(nm, L[[nm]], p)
environment(p[[nm]]) <- p
}
L
}
makefun3 <- function(flist) {
addtoenv(flist)
function() bar()
}
## 3) now we create the &q...