as.data.frame(NULL) & as.data.frame(list()) & bug in dput(.)

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

Subject: as.data.frame(NULL) & as.data.frame(list()) & bug in dput(.)
From: Martin Maechler (maechler@stat.math.ethz.ch)
Date: Mon 01 Nov 1999 - 18:39:11 EST


Message-ID: <14365.20911.924993.572835@gargle.gargle.HOWL>

{Connected to the bug report on expand.grid(.) and my fix to it..}

[Following the spirt of arrays where parts of dim() can be 0]
I would like for these two to give the "same"
or at least, both to give a data.frame with 0 observations of 0 variables.

Currently [R 0.65.1 and pre-0.90]

> str(d0 <- as.data.frame(list()))
    `data.frame': 0 obs. of 0 variable:
     list()

> dput(d0) ## BUG
    NULL

> as.data.frame(NULL)
    Error in as.data.frame.default(NULL) : can't coerce NULL into a data.frame

and
> str(dn0 <- as.data.frame(numeric(0)))
    `data.frame': 0 obs. of 1 variable:
     $ x: num

> dput(dn0)
    structure(list(x = numeric(0)), .Names = "x", class = "data.frame")

(S-plus 5.1 is almost the same, but uses "X" instead of "x" for a name)
-----

Comments?
If I don't get any, I'd only change as.data.frame such that
as.data.frame(NULL) === as.data.frame(list()) |--> 0 x 0 data.frame

Martin Maechler <maechler@stat.math.ethz.ch> http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum LEO D10 Leonhardstr. 27
ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND
phone: x-41-1-632-3408 fax: ...-1228 <><
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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