[R] Automatic re-looping after error

Achim Zeileis zeileis at ci.tuwien.ac.at
Thu Oct 9 20:09:14 CEST 2003


On Thursday 09 October 2003 19:03, Ted Harding wrote:

> Hi Folks,
> I'm seeking advice about how to resume an outer loop following
> failure of a function within the loop (which issues an error
> message).
>
> Essentially, I'm repeating (simulating) a process which involves
> random sampling, EM and MCMC. I'm walking on very edge of rather
> thin ice -- data rather thinly spread over many parameters!
>
> Occasionally some component of the loop fails, with an error
> message. At this point, R quits the run altogether and returns to
> the command prompt. I then have to restart the whole script.
>
> All that's really needed to cope with the situation is for R to
> drop that cycle of the loop, and resume with a new cycle.
>
> However, I'm wondering how to set this up. I've had a look at
> try(), and I'm not at all sure that it does what I would want.
> What I'd really like is something (inside the loop) on the lines of
>
>    on.error(maybe some parameters X) break
>
> where X might specify what sort of error or what function it comes
> from. Would setting
>
>   options(error = break )
>
> do it?
>
> Any other suggestions?

Look at try().

hth,
Z

> With thanks,
> Ted.
>
>
> --------------------------------------------------------------------
> E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
> Fax-to-email: +44 (0)870 167 1972
> Date: 09-Oct-03                                       Time: 18:03:37
> ------------------------------ XFMail ------------------------------
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help




More information about the R-help mailing list