6

Let consider a typical deparse(substitute( R call:

f1 <-function(u,x,y)
{print(deparse(substitute(x)))}

varU='vu'
varX='vx'
varY='vy'
f1(u=varU,x=varX,y=varY)

That results in

[1] "varX"

which is what we expect and we want.

Then, comes the trouble, I try to get a similar behaviour using the ... arguments i.e.

f2 <- function(...)
{  l <- list(...)
  x=l$x
  print(deparse(substitute(x))) ### this cannot work but I would like something like that
}

That, not surprisingly, does not work :

f2(u=varU,x=varX,y=varY)
[1] "\"vx\"" ### wrong ! I would like "varX"

I tried to get the expected behaviour using a different combination of solutions but none provides me what expected and it seems that I am still not clear enough on lazy eval to find myself the how-to in a resonable amount of time.

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
beuhbbb
  • 257
  • 3
  • 14

1 Answers1

7

You can get the list of all unevaluated arguments by doing

match.call(expand.dots = FALSE)$...

Or, if you only have dot arguments, via

as.list(match.call()[-1L])

This will give you a named list, similarly to list(...), but in its unevaluated form (similarly to what substitute does on a single argument).

An alternative is using rlang::quos(...) if you’re willing to use the {rlang} package, which returns a similar result in a slightly different form.

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214