I would like to read a bunch of csvs into a list in R
lol<-lapply(list.files()[c(grep(Sys.Date(),list.files()))],read.csv)
Some csv files are empty though so I get
Error in read.table(file = file, header = header, sep = sep, quote = quote, :
no lines available in input
(at least I think the error means)
How do I read the nonempty csv files into a list?
tryCatch does not work (or I am using it wrong)
tryCatch(toplel<-lapply(list.files()[c(grep(Sys.Date(),list.files()))],read.csv),error=function(e){print("lel")})
[1] "lel"
Try excluding empty files by their size:
files <- list.files()[c(grep(Sys.Date(),list.files()))]
files <- files[which(file.info(files)$size>0)]
lapply(files, read.csv)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With