Re: R-alpha: Two bugs reading data files

Peter Dalgaard BSA (pd@kubism.ku.dk)
30 Jan 1997 13:33:31 +0100


To: Peter Dalgaard BSA <pd@kubism.ku.dk>
Subject: Re: R-alpha: Two bugs reading data files
From: Peter Dalgaard BSA <pd@kubism.ku.dk>
Date: 30 Jan 1997 13:33:31 +0100
In-Reply-To: Peter Dalgaard BSA's message of 29 Jan 1997 15:07:54 +0100
Message-Id: <x23evjxrz8.fsf@bush.kubism.ku.dk>

Peter Dalgaard BSA <pd@kubism.ku.dk> writes:

> 
> 
> 1) I can't seem to get the as.is parameter to read.table to take:
> 
> > is.factor(read.table('data.txt',as.is=T)[,3])
> [1] TRUE
> > mode(read.table('data.txt',as.is=T)[,3])
> [1] "unordered"
> 
> That's not supposed to happen. Should be mode character, such as I
> read the docs - *and* the code for that matter... Problem seems to be
> that the implicit coercion to a data frame that happens when
> rownames(data) gets set, ALSO does the character->factor conversion
> thing. 

OK. I got a fix. Which uncovered another bug...
At the end of read.table, we see

	}
        row.names(data) <- row.names
        return(data)
}

Before the assignment of row.names, data is just a list of vectors,
provoking a coercion. However, this won't happen if you turn 'data'
into a data frame with class(data)<-"data.frame" first.

However, there's a bug in row.names<- :
> get("row.names<-")
function (x, value) 
{
        if (!is.data.frame(x)) 
                x <- data.frame(x, row.names = value)
        else attr(x, "row.names") <- as.character(value)
}

the "else" branch returns as.character(value) instead of x, so there's
a return(x) statement missing. Without the fix, you get this effect

> x<-data.frame(1:3,4:6)
> x
     X1 X2
[1,]  1  4
[2,]  2  5
[3,]  3  6
> row.names(x)<-7:9
> x
[1] "7" "8" "9"

(I get a sense of deja vue about this one. Reported before?)

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-testers mailing list -- For info or help, send "info" or "help",
To [un]subscribe, send "[un]subscribe"
(in the "body", not the subject !)  To: r-testers-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-