An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090219/12e500ea/attachment-0001.pl>
read.table : how to condition on error while opening file?
2 messages · Stephane Bourgeois, Eik Vettorazzi
Hi Stephane, see ?try hth. Stephane Bourgeois schrieb:
Hi,
I'm using read.table in a loop, to read in multiple files. The problem
is that when a file is missing there is an error message and the loop is
broken; what I'd like to do is to test for the error and simply do
"next" instead of breaking the loop. Anybody knows how to do that?
Example:
filelist <- c("file1.txt", "file2.txt", "file3.txt")
for (i in 1:3) {
if (read.table(filelist[i]) == ERROR LOADING FILE) {
# this is where I do not know how to write the condition
print(paste("error opening file ", filelist[i], sep=""))
next
} else {
tmp <- read.table(filelist[i])
}
}
Cheers,
Stephane
Eik Vettorazzi Institut f?r Medizinische Biometrie und Epidemiologie Universit?tsklinikum Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/42803-8243 F ++49/40/42803-7790