R-alpha: Two bugs reading data files

Peter Dalgaard BSA (pd@kubism.ku.dk)
29 Jan 1997 15:07:54 +0100

To: r-testers@stat.math.ethz.ch
Subject: R-alpha: Two bugs reading data files
From: Peter Dalgaard BSA <pd@kubism.ku.dk>
Date: 29 Jan 1997 15:07:54 +0100
Message-Id: <x2d8uofubp.fsf@bush.kubism.ku.dk>

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

> dd[[3]]<-as.character(dd[[3]]) 
> mode(dd[[3]])
[1] "unordered"

-- How DO you make a data frame contain a character vector ??
The following works, but...

(OK, OK, no big deal: just use as.character() where you need it. Bit
of a nuisance when you try to get factors defined right, though.)

2) This is a good ol' plain bug-a-boo:

scan('data.txt',list("",0,"","",0,0,"")) works first time only

> scan('data.txt',list("","","","",0,0,""))->j
Read 240 lines
> scan('data.txt',list("","","","",0,0,""))->j
Read 0 lines
> scan('data.txt')->j
Error: "scan" expected a real got "L"
> scan('data.txt',list("","","","",0,0,""))->j
Read 240 lines

after the 2nd command, j contains vectors of length 1000, full of
garbage. Only happens when 2nd argument is a list. 

BTW: More fun with factors.

> j<-factor(numeric(),levels=1:3)
> vi(j)
Error: attempt to coerce a vector to non-vector type

I swear I didn't change anything!

   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