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:

    > formals(fm)
   $x


   $y
   expr

though I expect g would be non-trivial to code up robustly.

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to