Re: expand.grid() (PR#301)

About this list Date view Thread view Subject view Author view Other groups

Subject: Re: expand.grid() (PR#301)
From: Jonathan Rougier (J.C.Rougier@durham.ac.uk)
Date: Sat 30 Oct 1999 - 01:38:30 EST


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


About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b25 : Tue 04 Jan 2000 - 14:16:09 EST