RE: [R] reading non-existing files

From: bogdan romocea <>
Date: Wed 08 Jun 2005 - 03:05:24 EST

if(!file.exists(your.file)) next

Or, try(): <- try(as.matrix(whatever))
if (class( == "try-error") {something went wrong / the file doesn't exist - just for logging, the code will not fail}

-----Original Message-----
From: Dave Evens [] Sent: Tuesday, June 07, 2005 12:48 PM
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"))


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

I would very much apprepriate any help.

Thanks in advance.


Get on-the-go sports scores, stock quotes, news and more. Check it out! mailing list PLEASE do read the posting guide! mailing list PLEASE do read the posting guide! Received on Wed Jun 08 03:17:48 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:27 EST