6

Is it possible to create a ellipsis (...) from a list? The idea is to be able to do something like:

mylist <- list(a=1,b=2,c=3)
myellipsis <- create_ellipsis(mylist)
print(switch('a', myellipsis)) # output 1
papirrin
  • 2,004
  • 22
  • 30

1 Answers1

9

You want do.call, which can pass the content of a list to a functions ... argument:

do.call(function(...) print(switch('a', ...)), mylist)
Roland
  • 127,288
  • 10
  • 191
  • 288
  • Amazing, know it seems so simple :-). Thanks! – papirrin Aug 31 '13 at 07:56
  • 1
    When your function specified other arguments, join their intended (overriding) values using `c( arg, arg, ..., myList )` as per [this answer](http://stackoverflow.com/a/10005644/1418999), for instance: `do.call(function(b=4, ...) print(switch('b', ...)), c(4, myList)) ` – krevelen Apr 10 '17 at 10:34