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

Martin Maechler Martin Maechler <maechler@stat.math.ethz.ch>
Mon, 1 Nov 1999 09:39:11 +0100 (MET)


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