Greetings,

Occasionally, I desire to call a function with one argument set to equal to another. Here is a toy example:

   f <- function(x, y) {

       x + y
   }

   f(x = 3, y = x) # Error in f(x = 3, y = x) : object 'x' not found

So far, the most concise way I found to accomplish this is:

   f(x = 3, y = local(sys.frame(1)$x)) # evaluates to 6

but I dislike this solution because local() creates a new environment. Surely there must be a better way?

Note: I'm not interested in solutions that require modifying or currying f.

Regards,
Ben

______________________________________________
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