From J.C.Rougier@durham.ac.uk  Fri Oct 29 16:38:30 1999
From: J.C.Rougier@durham.ac.uk (Jonathan Rougier)
Date: Fri, 29 Oct 1999 16:38:30 +0100 (BST)
Subject: expand.grid() (PR#301)
In-Reply-To: <199910291445.QAA13256@pubhealth.ku.dk>
Message-ID: <Pine.GSO.3.96.991029162251.1534F-100000@laplace>

On Fri, 29 Oct 1999 maechler@stat.math.ethz.ch wrote:

> Well, that is not quite true,
> 
>       expand.grid(NULL)  
> 
> gives NULL  without your change 
> but gives an error with your change...
> since
> 	data.frame(NULL)  
> fails.
> 
> The following (only this one of all 4 possibilities  as/no-as  x NULL/list() )
> would work
> 
> > as.data.frame(list())
> NULL data frame with 0 rows
> 
> ---
> Better patch ? (and what does S do ?)

Hmm ... Splus returns a data frame for a single variables or for a NULL
variable, the latter looking a bit strange:

> expand.grid(factor(c("L", "H")))
  Var1 
1    L
2    H
> expand.grid(NULL)                   
  Var1 
1   NA
0   NA

I think your patch is a good one.  So you would suggest

	if (nargs == 1)
	  return(if (is.null(args[[1]])) as.data.frame(list()) else
	    data.frame(args))

Cheers, Jonathan.

Jonathan Rougier                       Science Laboratories
Department of Mathematical Sciences    South Road
University of Durham                   Durham DH1 3LE

"[B]egin upon the precept ... that the things we see are to be 
 weighed in the scale with what we know"  (Meredith, 1879, The Egoist)

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


expand.grid() (PR#301)
Jonathan Rougier