[Rd] Bug(s) w/ rbind.data.frame(); fix also read.table(*, as.is = TRUE) ? (PR#669)

maechler@stat.math.ethz.ch maechler@stat.math.ethz.ch
Mon, 25 Sep 2000 10:17:02 +0200 (MET DST)


This is not only bug report, but also a RFC (request for comments):

The basic problem is that there are (at least) two ways of easily getting
non-factor character columns in data.frames.
The first is  
    read.table(*, as.is = TRUE) 
and the second is
    data.frame(.., I(...), ..)	      

which differ in their result. Whereas the first produces `pure' character
columns in the data.frame, the second approach gives `AsIs' classed
columns (character, or, e.g. logical).

Now, as the following shows,  rbind.data.frame()  *is* buggy anyway,
I wonder if we shouldn't change read.table(*, as.is = TRUE)
such that the non-numeric columns of its result become "AsIs" classed as
well:

-----------

str(d1 <- data.frame(a=1:3, b = I(letters[1:3])))
## d1 is `alright'
## d0: The same but a `character' *not* protected by AsIs:
d0 <- d1
d0$b <- unclass(d0$b)
str(d0)
## Note that this is *really* the same as a what you get from
##  read.table(*, as.is = TRUE)
##  ----------
##  R's read.table() is S+ compatible; however I wonder if
##  we shouldn't add  "AsIs" classes to all non-numeric components...
##  the classes, shouldn't harm, but ensure consistency of treatment..

str(d11 <- rbind(d1, new = c(7, "N"))) ## alright
str(d01 <- rbind(d0, new = c(7, "N"))) ## all wrong :
## Both columns were coerced to factors !!
##-- S-PLUS 5 coerces both to "character" -- which is better,
##  since the new row *is* all character

## R makes nonsense with 'b' [factor w/ 1 level "N": NA NA NA 1]
## S+ 5.1 does exactly the right thing [both a & b still look like in d0,d1 :
str(d12 <- rbind(d1, new = data.frame(a= 7, b="N")))##
str(d02 <- rbind(d0, new = data.frame(a= 7, b="N")))##

---------

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