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.

2
  • r u looking for f2 <- function(...) as.character(as.list(match.call())$x)?
    – chinsoon12
    Commented Mar 6, 2019 at 9:39
  • @chinsoon12 Thks this is working !
    – beuhbbb
    Commented Mar 6, 2019 at 10:15

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.