[Rd] Mishandling missing "..." (PR#1247)

Thomas Lumley tlumley@u.washington.edu
Mon, 7 Jan 2002 11:14:33 -0800 (PST)


On Mon, 7 Jan 2002 brahm@alum.mit.edu wrote:

> R> myfun <- function(x, ...) {x[...] <- 0; x}
> R> myfun(3)
>    Error in myfun(3) : SubAssignArgs: invalid number of arguments
>
> It fails because no ... was passed.  The workaround (and desired behavior) is:
> R> myfun <- function(x, ...) {if (missing(...)) x[] <- 0 else x[...] <- 0; x}
> R> myfun(3)
>    [1] 0
>

This is interesting.  Another workaround is

> myfun
function(x, ...) {x[...] <- 0; x}
> myfun(3,)
[1] 0

and the problem goes down to eval.c:evalListKeepMissing, which says
	/* If we have a ... symbol, we look to see what it is bound to.
	 * If its binding is Null (i.e. zero length)
	 *	we just ignore it and return the cdr with all its
               expressions evaluated;

The difference between  myfun(3) and myfun(3,) is that in the former case
there are no ... arguments, in the latter there is a ... argument but it's
missing.

In one way this would be fairly easy to fix by writing yet another variant
of evalList that replaced an empty ... with R_MissingArg, but I'm scared.


	-thomas

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._