[R] reading non-existing files

2005-06-07 Thread Dave Evens

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


RE: [R] reading non-existing files

2005-06-07 Thread bogdan romocea
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


Re: [R] reading non-existing files

2005-06-07 Thread Patrick Connolly
On Tue, 07-Jun-2005 at 09:48AM -0700, Dave Evens wrote:

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

Try try().

Use a condition on what you get back to avoid attempting to do things
to empty files.

?try will be a good place to start.

-- 
Patrick Connolly
HortResearch
Mt Albert
Auckland
New Zealand 
Ph: +64-9 815 4200 x 7188
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~
I have the world`s largest collection of seashells. I keep it on all
the beaches of the world ... Perhaps you`ve seen it.  ---Steven Wright 
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~

__
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