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

Jeff Newmiller jdnewmil at dcn.davis.ca.us
Tue Aug 31 07:31:22 CEST 2010


Perhaps ?try can help...

"Paul" <p.franklin at niwa.co.nz> wrote:

>
>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.
>
>______________________________________________
>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.

---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.



More information about the R-help mailing list