Skip to content
Prev 78733 / 398502 Next

problem with lapply(x, subset, ...) and variable select argument

The problem is that subset looks into its parent frame but in this
case the parent frame is not the environment in tt but the environment
in lapply since tt does not call subset directly but rather lapply does.

Try this which is similar except we have added the line beginning
with environment before the print statement.

tt <- function (n) {
   x <- list(data.frame(a=1,b=2), data.frame(a=3,b=4))
   environment(lapply) <- environment()
   print(lapply(x, subset, select = n))
}

n <- "b"
tt("a")

What this does is create a new version of lapply whose
parent is the environment in tt.
On 10/10/05, joerg van den hoff <j.van_den_hoff at fz-rossendorf.de> wrote: