[R] help with tryCatch

2007-02-12 Thread Stephen Bond
Could smb please help with try-catch encapsulating a function for downloading. Let's say I have a character vector of symbols and want to download each one and surround by try and catch to be safe # get.hist.quote() is in library(tseries), but the question does not depend on it, I could be sour

Re: [R] help with tryCatch

2007-02-12 Thread Henrik Bengtsson
See ?tryCatch. /Henrik On 2/12/07, Stephen Bond <[EMAIL PROTECTED]> wrote: > Could smb please help with try-catch encapsulating a function for > downloading. Let's say I have a character vector of symbols and want to > download each one and surround by try and catch to be safe > > # get.hist.quote

Re: [R] help with tryCatch

2007-02-13 Thread Henrik Bengtsson
Hi, google "R tryCatch example" and you'll find: http://www.maths.lth.se/help/R/ExceptionHandlingInR/ Hope this helps Henrik On 2/13/07, Stephen Bond <[EMAIL PROTECTED]> wrote: > Henrik, > > I had looked at tryCatch before posting the question and asked the > question because the help file w

Re: [R] help with tryCatch

2007-02-13 Thread Stephen Bond
Henrik, thank you for the reference. Can you please tell me why the following does not work? vec=c("hdfhjfd","jdhfhjfg")# non-existent file names catch=function(vec){ tryCatch({ ans =NULL;err=NULL; for (i in vec) { source(i) ans=c(ans,i) } }, interrupt=function(

Re: [R] help with tryCatch

2007-02-13 Thread Henrik Bengtsson
Put the for loop outside the tryCatch(). /H On 2/13/07, Stephen Bond <[EMAIL PROTECTED]> wrote: > Henrik, > > thank you for the reference. Can you please tell me why the following > does not work? > > vec=c("hdfhjfd","jdhfhjfg")# non-existent file names > catch=function(vec){ > tryCatch({ >

Re: [R] help with tryCatch

2007-02-13 Thread Henrik Bengtsson
To be more precise, put the tryCatch() only around the code causing the problem, i.e. around source(). /H On 2/13/07, Henrik Bengtsson <[EMAIL PROTECTED]> wrote: > Put the for loop outside the tryCatch(). /H > > On 2/13/07, Stephen Bond <[EMAIL PROTECTED]> wrote: > > Henrik, > > > > thank you for

Re: [R] help with tryCatch

2007-02-15 Thread Stephen Bond
Henrik, Please, stay with me. there is a problem with the way tryCatch processes statements and that is exactly what the help file does not describe at all. I am trying catch=function(vec){ ans=NULL;err=NULL; for (i in vec) { tryCatch({ source(i); ans=c(

Re: [R] help with tryCatch

2007-02-15 Thread Henrik Bengtsson
Note that the error catch is calling your locally defined function. Like anywhere in R, if you assign something to a variable inside a function, it only applies there and not "outside". The quick a dirty fix is to do: err <<- c(err, er) /H On 2/15/07, Stephen Bond <[EMAIL PROTECTED]> wrote: >