[R] tryCatch - return from function to main script

From: Anne-Marie Ternes <amternes_at_gmail.com>
Date: Tue, 15 Jul 2008 12:59:37 +0200


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. Received on Tue 15 Jul 2008 - 11:03:05 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 - 22:31:44 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