[R] Error handling

Gabor Grothendieck ggrothendieck at gmail.com
Mon May 23 23:38:21 CEST 2005

On 5/23/05, Carsten Steinhoff <carsten.steinhoff at gmx.de> wrote:
> Hi,
> I have written an R-Procedure that automatically does a ML-Fit for some
> datasets to a few
> selected distributions. After any optimization the function writes the
> estimated parameters into a variable.
> My problem is now that sometimes the optimization failes and my program
> stops with an error message.
> What I want after a failed optimization is that there is written an error
> msg
> in the variable instead of stopping the program.
> For the ML-Fit I use the "fitdistr" algorithm.



For example, using try:

result <- try(myfun(...whatever...))
if(inherits(result, "try-error")) ...process the error...

More information about the R-help mailing list