This is a very minor point and I hesitate to call it a bug, but might I suggest modifying the nargs=1 return statement in expand.grid() from if (nargs == 1) return(args[[1]]) to if (nargs == 1) return(data.frame(args)) so that the result of expand.grid is always a data frame (as indicated in the help file). This also preserves the variable name if it exists. 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>>>>> "JonR" == J C Rougier <J.C.Rougier@durham.ac.uk> writes:JonR> This is a very minor point and I hesitate to call it a bug, but JonR> might I suggest modifying the nargs=1 return statement in JonR> expand.grid() from JonR> if (nargs == 1) return(args[[1]]) JonR> to JonR> if (nargs == 1) return(data.frame(args)) JonR> so that the result of expand.grid is always a data frame (as JonR> indicated in the help file). This also preserves the variable JonR> name if it exists. 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 ?) Martin -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._