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? 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 ------------------------------
Have you considered "try"? hope this helps. spencer graves (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? > >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 > >
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
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?Argh, didn't read carefully enough, sorry. Usually, I would expect from your description that try() would be good enough. You can "try()" the critical functions inside the loop and modify the actions inside the loop accordingly if something goes wrong... Z> Any other suggestions? > > 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
On Thu, 9 Oct 2003 Ted.Harding at nessie.mcc.ac.uk wrote:> 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 ) >I don't think so. You may need to look at the new exception-handling code (start with help(tryCatch)). -thomas