[R] How to program an error into an if-then statement

Dimitri Liakhovitski dimitri.liakhovitski at gmail.com
Tue Nov 9 17:55:54 CET 2010


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
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:

if "cannot open the connection" - then do X

What statement should I use under "if"?

Thanks a lot!

Dimitri Liakhovitski
Ninah Consulting

More information about the R-help mailing list