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

Dieter Menne dieter.menne at menne-biomed.de
Wed Sep 1 15:20:17 CEST 2010



Paul wrote:
> 
> Thanks for the responses. 'Try' seems to be the function that I needed. I
> had to adapt the code suggested below because vapply wasn't recognised,
> but this seemed to work:
>   x<‑lapply(a,function(x){try(read.table(x,colClasses='character'))})
> 

There is the risk with this approach that you could miss a real error in
your data (e.g. character in the wrong place, truncated). I would prefer to
use file.info to get the file size before I open it, and skip if too small.

Dieter

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



More information about the R-help mailing list