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
______________________________________________
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.