Skip to content
Prev 219622 / 398500 Next

Lazy evaluation in function call

Thorn wrote:
I don't know if you can do that.  You'd need something like


f <- function(x, y) x+y

f(x, get("x", environment()))

but it doesn't work.  The problem is you need access to the evaluation 
frame of f, which doesn't exist before you call the function, so you 
need to use lazy evaluation to find it after it has been created.  I 
guessed that environment() would see it, but I was wrong:  that is 
evaluated in the calling environment, so it sees that.

I'm not sure if there's some devious way to do this, but I'd certainly 
recommend against ever using it.  To solve your original problem, just 
make a copy of the function and modify it.

Duncan Murdoch