How can I write a function to capture the dot-dot-dot (ellipsis) and return a list of unevaluated expressions?
In this example, the user supplies expressions in curly braces, and receives the output I need:
fun1 <- function(...) {
as.list(substitute(list(...)))[-1L]
}
fun1({a = 2}, {a2 = a * 2})
> [[1]]
> {
> a = 2
> }
>
> [[2]]
> {
> a2 = a * 2
> }
I would like the user to make the same call as above without curly braces and receive the same output as in fun1()
:
fun2 <- function(...) {
# CODE HERE
}
fun2(a = 2, a2 = a * 2)