[R] Skipping missing files when importing data

jiangrm jiangrm at gmail.com
Mon Sep 21 06:28:25 CEST 2009


Trying to import a bunch of data files named like f001, f002, ....f999. Some of the files may be
missing and the missing files vary from time to time.

Used for loop and read.table. When it reaches the missing file (say f100), it shows:

Error in file(file, "r") : cannot open the connection
In addition: Warning message:
In file(file, "r") :
  cannot open file 'f100': No such file or directory

and the program stops.

How can I skip the missing ones and keep the program running? Guess either checking the validity of
filenames, or ignore the error message may work. Which functions should be used or any better ideas?


-RJ




More information about the R-help mailing list