Take a look in ?try and ?tryCatch myfile <- tryCatch(read.csv(myfilename), error = invisible) myfile$message
On Tue, Nov 9, 2010 at 2:55 PM, Dimitri Liakhovitski < dimitri.liakhovit...@gmail.com> wrote: > Hello! > > I am running a loop (for a range of dates) and in this loop I am > reading in different files - based on a date that is part of the file > name. > However, for some of the dates, I have no file (no way to know which > dates). So, when I try to read it in I get an error: > > Error in file(file, "rt") : cannot open the connection > > Question: I'd like to program an if-then statement in my code that > says something like this: > > myfile<-read.csv(myfilename) > if "cannot open the connection" - then do X > > What statement should I use under "if"? > > Thanks a lot! > > > -- > Dimitri Liakhovitski > Ninah Consulting > www.ninah.com > > ______________________________________________ > R-help@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. > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
______________________________________________ R-help@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.