Re: [R] Error handling

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Tue 24 May 2005 - 07:38:21 EST

On 5/23/05, Carsten Steinhoff <carsten.steinhoff@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.
>

See

?try
?tryCatch

For example, using try:

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



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue May 24 07:41:17 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:01 EST