[R] tryCatch - return from function to main script
jim holtman
jholtman at gmail.com
Wed Jul 16 00:20:50 CEST 2008
Can you provide an example of what you have tried. This should work:
for(i in 1:4){
x <- try(yourFunction(...))
if (class(x) = "try-error") print('had a problem")
}
On Tue, Jul 15, 2008 at 6:59 AM, Anne-Marie Ternes <amternes at gmail.com> wrote:
> Dear helpers,
>
> I've got a main script, which calls 4 times a function on 4 different
> datasets respectively. This function runs "nls" and is located in
> another R script which is sourced into my main script.
>
> What I would like to have is this:
>
> If, e.g. in the 3rd call of the function, nls fails, because it can't
> converge, I would like it to return an error (value or message), and
> continue with the 4th call in my main script.
>
> I've tried "try", but it always completely stops execution. I've also
> played around with "tryCatch", but to be honest, the help page is
> quite cryptic to me. I'm sure "tryCatch" has a way of being told to
> "ok, stop this, and continue with the main script".
>
> As I'm quite in a hurry (need to finish this before leaving tomorrow),
> I'd be glad if you could give me a very practical example - I promise
> to look deeper into the details of exception handling in R when I'm
> back.
>
> Thanks a lot!!
>
> Anne-Marie
>
> ______________________________________________
> R-help at r-project.org 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.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem you are trying to solve?
More information about the R-help
mailing list