Dear list Can anyone suggest a simple way to abort execution like stop(...) does, but without issuing an "Error: ..." message? I don't want to set 'options( show.error.messages=TRUE)' because I want normal behaviour to resume after this particular stop. (Please reply personally as well as to the list, as I'm not subscribed to R-help) Thanks Mark -- Mark Bravington CSIRO Mathematical & Information Sciences Marine Laboratory Castray Esplanade Hobart 7001 TAS ph (+61) 3 6232 5118 fax (+61) 3 6232 5012 mob (+61) 438 315 623
Dear Mark, How about something like this?> f <- function(x){+ if (x < 0){ + opt <- options(show.error.messages=FALSE) + on.exit(options(opt)) + stop() + } + sqrt(x) + }> > f(2)[1] 1.414214> f(-2) >I hope this helps, John ------------------------------ John Fox, Professor Department of Sociology McMaster University Hamilton, Ontario, Canada web: socserv.mcmaster.ca/jfox> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]On> Behalf Of Mark.Bravington at csiro.au > Sent: November-10-08 5:42 PM > To: R-help at r-project.org > Cc: Mark.Bravington at csiro.au > Subject: [R] how to stop without error message? > > Dear list > > Can anyone suggest a simple way to abort execution like stop(...) does,but> without issuing an "Error: ..." message? > > I don't want to set 'options( show.error.messages=TRUE)' because I want > normal behaviour to resume after this particular stop. > > (Please reply personally as well as to the list, as I'm not subscribed toR-> help) > > Thanks > Mark > > -- > Mark Bravington > CSIRO Mathematical & Information Sciences > Marine Laboratory > Castray Esplanade > Hobart 7001 > TAS > > ph (+61) 3 6232 5118 > fax (+61) 3 6232 5012 > mob (+61) 438 315 623 > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
On Mon, Nov 10, 2008 at 4:42 PM, <Mark.Bravington at csiro.au> wrote:> Dear list > > Can anyone suggest a simple way to abort execution like stop(...) does, but without issuing an "Error: ..." message? > > I don't want to set 'options( show.error.messages=TRUE)' because I want normal behaviour to resume after this particular stop.What's wrong with return() ? Hadley -- http://had.co.nz/
Not sure if this qualifies as simple but you can use callCC to force an
exit from within an inner call. In this example we call f which calls f1
which calls f2 and then f2 exits right out to the top level returning 0.
Note that f2 must know about g:
f <- function(g) {
f1 <- function() {
cat("A\n")
f2()
cat("B\n")
}
f2 <- function() {
cat("a\n")
g(0)
cat("b\n")
}
f1()
}
callCC(f)
On Mon, Nov 10, 2008 at 5:42 PM, <Mark.Bravington at csiro.au>
wrote:> Dear list
>
> Can anyone suggest a simple way to abort execution like stop(...) does, but
without issuing an "Error: ..." message?
>
> I don't want to set 'options( show.error.messages=TRUE)'
because I want normal behaviour to resume after this particular stop.
>
> (Please reply personally as well as to the list, as I'm not subscribed
to R-help)
>
> Thanks
> Mark
>
> --
> Mark Bravington
> CSIRO Mathematical & Information Sciences
> Marine Laboratory
> Castray Esplanade
> Hobart 7001
> TAS
>
> ph (+61) 3 6232 5118
> fax (+61) 3 6232 5012
> mob (+61) 438 315 623
>
> ______________________________________________
> 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.
>