[R] Reading multiple text files where some files are empty

Paul p.franklin at niwa.co.nz
Tue Aug 31 06:47:43 CEST 2010


Hi All,

I have a problem with reading in multiple text files where some of the files
have no data and was hoping someone may be able to help me find a solution.

Each text file is a daily log of fish movement. However, on some occasions
no movements will be recorded on a particular day and therefore the text
file for that day is empty.

I'm currently using the following code to read the files:

a<-list.files()
x<-lapply(a,function(x){read.table(x,colClasses='character')}) #the
colClasses is to ensure zeros at the beginning of tag numbers are included
myData<-do.call(rbind, x)

This works fine as long as all the files being read have data in them, but
if one of the empty log files is included it returns the following error:

Error in read.table(x, colClasses = "character", blank.lines.skip = TRUE) : 
  no lines available in input

Does anyone know of a way that I can overcome this (maybe skip empty files
somehow?) without having to manually trawl through the hundreds of files I
have to remove the empty ones?

Thanks in advance,
Paul

-- 
View this message in context: http://r.789695.n4.nabble.com/Reading-multiple-text-files-where-some-files-are-empty-tp2401035p2401035.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list