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]]

