Skip to content
Prev 43741 / 63424 Next

Convenience function to get unevaluated ... function arguments

Folks:

Herein is a suggestion for a little R convenience function mainly to
obtain unevaluated ... function arguments. It arose from a query on
R-help on how to get these arguments. The standard (I think) idiom to
do this is via

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

However, Bill Dunlap pointed out that this repeats the argument
matching of the function call and suggested a couple of alternatives
that do not, one of which I've adapted as the following function,fun
(I'll comment on naming in a second):

fun <- as.list(substitute((...), env = parent.frame()))[-1]

Typical usage would be:

f <- function(x, ...,y)fun()

e.g.
$z
sin(a)

[[2]]
stop("oh")

$w
warning("Yikes")

It turns out that (surprisingly to me) the substitute idiom is faster
than the match.call idiom, although the difference appears
unimportant, since both are so fast. And it is a little slower when
wrapped into a function, anyway -- I wasn't able to figure out a
convenient way to wrap the match.call version into a function.

The question is where -- if anywhere -- should this little one-liner
go? Seems to me that there are 3 possibilities:
1. Nowhere. Unnecessary and trivial.  An entirely reasonable response,
imho; I leave it to guRus to make this judgment.

2. In with match.call(); in which case a name like match.dots would
seem appropriate.

3. In with substitute(); in which case something like substituteDots
to make the relationship clear might be appropriate.

If R core or others do want to use this, I would be happy to write the
line or two of additional documentation required (if no one else wants
to).

And to repeat... I know this is trivial, so no explanation or response
is needed if it is decided to ignore it.

Best,
Bert