From tlumley@u.washington.edu  Mon Jan  7 19:14:33 2002
From: tlumley@u.washington.edu (Thomas Lumley)
Date: Mon, 7 Jan 2002 11:14:33 -0800 (PST)
Subject: [Rd] Mishandling missing "..." (PR#1247)
In-Reply-To: <200201071552.QAA00375@pubhealth.ku.dk>
Message-ID: <Pine.A41.4.43.0201071110230.157118-100000@homer04.u.washington.edu>

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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


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