hadley / lazyeval

Lazy evaluation: an alternative to non-standard evaluation (NSE) for R
131 stars 40 forks source link

should f_eval() allow data to be an environment? #71

Closed rpruim closed 8 years ago

rpruim commented 8 years ago

It would be nice if this worked:

foo <- function(x, data = parent.frame()) {
  lx <- lazyeval::f_capture(x)
  lazyeval::f_eval(lx, data)
}

foo(a ~ b)
##  Error: Do not know how to find data associated with `x` 
foo(5)
##  Error: Do not know how to find data associated with `x` 
hadley commented 8 years ago

I don't think that's possible - that would introduce two stacks of environments.

Do you have a more realistic example? The whole point is avoid using parent.frame() because it's not reliable.

rpruim commented 8 years ago

Actually, I may be able to refactor to avoid this since f_capture(x) will capture the environment and I can make the default value of data be NULL. I'll see if I can get that to work.