Re: [R] tryCatch - return from function to main script

From: jim holtman <jholtman_at_gmail.com>
Date: Tue, 15 Jul 2008 18:20:50 -0400

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?

______________________________________________
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.
Received on Tue 15 Jul 2008 - 22:24:14 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 15 Jul 2008 - 23:32:04 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive