file.exists(): if(!file.exists(your.file)) next Or, try(): your.data <- try(as.matrix(whatever)) if (class(your.data) == "try-error") {something went wrong / the file doesn't exist - just for logging, the code will not fail}
-----Original Message----- From: Dave Evens [mailto:[EMAIL PROTECTED] Sent: Tuesday, June 07, 2005 12:48 PM To: r-help@stat.math.ethz.ch Subject: [R] reading non-existing files Dear all, I'm trying to read to a collection of files in a loop using odbcConnectExcel - but not all of the files exist. This is the code I have for(i in 1:no.of.subs){ channel <- odbcConnectExcel(paste(working.dir, subs[i], ".xls", sep="")) datafiles[[i]] <- as.matrix(sqlFetch(channel, "Data")) close(channel) } I'm not sure how to alter the code to allow for the fact that some files may not exist - these files should be ignored. Currently, I get the following error Error in odbcTableExists(channel, sqtable) : 'Data': table not found on channel - it however creates an empty file for the first occurance of a non-existing file then stops. I would very much apprepriate any help. Thanks in advance. Dave __________________________________ Get on-the-go sports scores, stock quotes, news and more. Check it out! ______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html ______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html