[R] chaining closure arguments on-the-fly
btyner @end|ng |rom gm@||@com
Sun Jun 21 17:37:27 CEST 2020
On 6/20/20 5:04 PM, Duncan Murdoch wrote:
> I think you effectively did that in your original post (all but
> encapsulating the expression in a function), so yes, it's possible.
> However, it's a really bad idea. Why use non-standard evaluation when
> standard evaluation is fine? Standard evaluation follows some well
> defined rules, and is easy to reason about. NSE follows whatever
> rules it wants, so it's really hard for users to follow. For example,
> assuming you had the g() you want, what would this give?
> z <- 3
> f(x = z, y = g(z))
> You can't possibly know that without knowing whether there's a local
> variable in f named z that is created before y is evaluated.
> Duncan Murdoch
Very good point, and I agree it's best to use standard evaluation
whenever possible. The role of g would essentially be to modify one or
more elements of f's formals in-place. For example calling:
f(x = 3, y = g(expr))
would be equivalent to calling a function fm:
fm(x = 3)
where the body of fm is identical to that of f, but:
though I expect g would be non-trivial to code up robustly.
More information about the R-help