If I want to know what is stored in a ...
argument within an R function, I can simply convert it to be a list, like so
foo <- function(...)
{
dots <- list(...)
print(dots)
}
foo(x = 1, 2, "three")
#$x
#[1] 1
#
#[[2]]
#[1] 2
#
#[[3]]
#[1] "three"
What I can't figure out is how to evaluate ...
in the calling function. In this next example I want the contents of baz
to return the ...
argument to bar
.
bar <- function(...)
{
baz()
}
baz <- function()
{
# What should dots be assigned as?
# I tried
# dots <- get("...", envir = parent.frame())
# and variations of
# dots <- eval(list(...), envir = parent.frame())
print(dots)
}
bar(x = 1, 2, "three")
get("...", envir = parent.frame())
returns <...>
, which looks promising, but I can't figure out how to extract anything useful from it.
eval(list(...), envir = parent.frame())
throws an error, claiming that ...
is used incorrectly.
How can I retrieve the ...
from bar
?