[R] read.table not clearing colClasses

From: Skewes,Aaron <ASkewes_at_mdanderson.org>
Date: Tue, 11 Nov 2008 14:34:19 -0600


I am attempting to created colClasses for several tables, then read only specific columns. There are two different table layouts that I am working with. If I use exclusively one layout, the script works perfectly, but if I mix the layouts, it fails to grab the correct columns form layout that is read in second. It appears that colClasses fails to adopt the new structure after the first iteration. Is there some way to clear colClasses of flush the write buffer between iterations?

Thanks,
Aaron

for(i in 1:length(fullnames.in))

        {
                cnames<- read.table(fullnames.in[i], header=FALSE, sep="\t", na.strings="", nrows=1, row.names = NULL
                        , skip=9, fill=TRUE, quote="")


#initialize col.classes to NULL vector
seq(1,length(cnames))->column.classes column.classes[1:length(cnames)]="NULL"
#find where the desired columns are
idx<-which(cnames=="Row") column.classes[idx]="integer" idx<-which(cnames=="Col") column.classes[idx]="integer" idx<-which(cnames=="ControlType") column.classes[idx]="integer" idx<-which(cnames=="ProbeName") column.classes[idx]="character" idx<-which(cnames=="GeneName") column.classes[idx]="character" idx<-which(cnames=="SystematicName") column.classes[idx]="character" idx<-which(cnames=="LogRatio") column.classes[idx]="numeric" idx<-which(cnames=="gMeanSignal") column.classes[idx]="numeric" idx<-which(cnames=="rMeanSignal") column.classes[idx]="numeric" idx<-which(cnames=="gBGMeanSignal") column.classes[idx]="numeric" idx<-which(cnames=="rBGMeanSignal") column.classes[idx]="numeric" print(fullnames.in[i]) print("Reading file, this could take a few minutes")
#read all rows of selected columns into data.frame
d <- read.table(fullnames.in[1], header=TRUE, sep="\t", na.strings="", nrows=number.rows, colClasses=column.classes, row.names = NULL , skip=9, fill=TRUE, quote="") print("Writing file, this could take a few minutes")
#write all rows of selected columns into file
write.table(d, fullnames.out[i], sep="\t", quote=FALSE, row.names=FALSE) rm(cnames, column.classes, d, idx) } [[alternative HTML version deleted]] ______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Tue 11 Nov 2008 - 20:39:12 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 11 Nov 2008 - 21:30:24 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive