RE: [R] reading non-existing files

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


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:devens8765@yahoo.com] 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

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