There are 4 ways, other than generating a core dump :-), that could
fit your vague desctiption:

    Call q("no"); this is the only way to avoid 'finally' expressions
    in tryCatch if that is really what you want.

    You can invoke an "abort" restart; there will be one established
    by the intepreter, but there may be others. You can choose the
    one you want programmatically.  If you use the outer-most one
    from the interpreter then what happens depends on whether R is
    running interactively or not.

    You can call stop() with a condition argument that is not an error
    or a warning to avoid any handlers established by tryCatch or
    withCallingHandlers to intercept warnings or errors. This will
    drop down to stop's default handling of errors (i.e. print a
    message and invoke the nearest "abort" restart).

    You can capture an unevaluated return() call and evaluate it at
    the point from which you want to escape. This is what callCC does,
    and using callCC would be the recommended way to do this if this
    is what you want.

[R's condition handling is based on Common Lisp's; a good reference
for that is
http://www.nhplace.com/kent/Papers/Condition-Handling-2001.html. Some
day there will be an R version of this document.]

What choice is appropriate depends on exactly what you want to have
happen after you execute your "Hard Stop" and whether you own, or need
to own, the code that receives the transfer of control initiated by
your 'Hard Stop".

Best,

luke

On Thu, 7 Feb 2013, Duncan Murdoch wrote:

On 06/02/2013 8:33 PM, ivo welch wrote:
is it possible to throw a stop() that is so hard that it will escape
even tryCatch?

You can signal a condition that is not an error, and if tryCatch hasn't been written to catch it, it will stop. For example,

g <- function() {
 tryCatch(f(), error=function(e) NULL
 cat("Still running\n")
}

f <- function() stop("Regular error")  # This won't stop g()
g()


f  <- function() stop(simpleCondition("I mean it!")) # This will
g()

Of course, you can catch simpleConditions too if you try.

Duncan Murdoch

______________________________________________
R-help@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.


--
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa                  Phone:             319-335-3386
Department of Statistics and        Fax:               319-335-3017
   Actuarial Science
241 Schaeffer Hall                  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu

______________________________________________
R-help@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.

Reply via email to