Skip to content
Prev 27871 / 63424 Next

merging environments

2008/3/7 Ben Bolker <bolker at zoo.ufl.edu>:
I think you're doomed to be ugly if you don't use closures - I think
any explicit manipulation of environments is worse than the implicit
manipulation by closures.

f <- function(data) with(data, x + y + z)
f2 <- function(fun, data) function() fun(data)

f2(f, list(x = 10))()

Although it would be even nicer if you could do:

f <- function()  x + y + z
f2 <- function(fun, data) function() with(data, fun())

but I think that's confusing different types of scoping.

Hadley