[Rd] Possible documentation problem/bug?

Dominic Littlewood 11d||tt|ewood @end|ng |rom gm@||@com
Thu Apr 30 14:31:08 CEST 2020


It seems like there is no obvious way in the documentation to convert the
expressions in the dots argument to a list without evaluating them. Say, if
you want to have a function that prints all its arguments:

> foo(abc$de, fg[h], i)
abc$de
fg[h]
i

...then converting them to a list would be helpful.
Using substitute(...) was the first thing I tried, but that only gives
the *first
*argument in dots. It turns out that there is a way to do this, using
substitute(...()), but this does not appear to be in either the substitute or
the dots help page.

In fact, there is a clue how to do this in the documentation, if you look
closely. Let me quote the substitute page:

"Substituting and quoting often cause confusion when the argument is
expression(...). The result is a call to the expression constructor
function and needs to be evaluated with eval to give the actual expression
object."

So this appears to give a way to turn the arguments into a list -
eval(substitute(expression(...))).  But that's quite long, and hard to
understand if you just come across it in some code - why are we using eval
here? why are we substituting expression? - and would definitely require an
explanatory comment. If the user just wants to iterate over the arguments,
substitute(...()) is better. In fact, you can get exactly the same effect
as the above code using as.expression(substitute(...())). Should the
documentation be updated?

	[[alternative HTML version deleted]]



More information about the R-devel mailing list