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 was not adequate for me. Could you pls > provide a sample code of > try{ try code} > catch(error){catch code} > > let's say you have a vector of local file names and want to source them > encapsulating in a tryCatch to avoid the skipping of all good file names > after a bad file name. > > thank you > stephen > > > Henrik Bengtsson wrote: > > > 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() is in library(tseries), but the question does not > >> depend on it, I could be sourcing local files instead > >> > >> ans=null;error=null; > >> for ( sym in sym.vec){ > >> try(ans=cbind(ans,get.hist.quote(sym,start=start))) #accumulate in a zoo > >> matrix > >> catch(theurlerror){error=c(error,sym)} #accumulate failed symbols > >> } > >> > >> I know the code above does not work, but it conveys the idea. tryCatch > >> help page says it is similar to Java try-catch, but I know how to do a > >> try-catch in Java and still can't do it in R. > >> > >> Thank you very much. > >> stephen > >> > >> ______________________________________________ > >> [email protected] mailing list > >> https://stat.ethz.ch/mailman/listinfo/r-help > >> PLEASE do read the posting guide > >> http://www.R-project.org/posting-guide.html > >> and provide commented, minimal, self-contained, reproducible code. > >> > ______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
