abort: Aborts the current expression call

Description Usage Arguments Details Value Author(s) References See Also Examples

Description

Aborts the current expression call and returns to the top level prompt/browser without signaling a condition.

Usage

1
2
## Default S3 method:
abort(..., call.=TRUE, domain=NULL)

Arguments

...

(optional) Objects coerced to character and pasted together without a separator, or a @condition object. If no object are given, no message is printed.

call.

If TRUE, the call is added to the message, otherwise not.

domain

Used to translate the message (see gettext()). If NA, messages will not be translated.

Details

There are still cases where one can "catch" the abort and undo it, cf. [1].

Value

Returns nothing.

Author(s)

Henrik Bengtsson

References

[1] R-devel thread ”, Sept 11, 2012, https://stat.ethz.ch/pipermail/r-devel/2012-September/064838.html.

See Also

throw(). stop(). Internally, invokeRestart()("abort") is utilized.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
## Not run: 
 foo <- function() {
  cat("foo()...\n")
  on.exit(cat("foo()...done\n"))
  tryCatch({
    stop("Woops!")
  }, error = function(ex) {
    cat("An error was caught: ", ex$message, "\n", sep="")
  })
  cat("Continuing...\n")
}

bar <- function() {
  cat("bar()...\n")
  on.exit(cat("bar()...done\n"))
  tryCatch({
    abort("Woops!")
  }, error = function(ex) {
    cat("An error was caught: ", ex$message, "\n", sep="")
  })
  cat("This message will never be displayed...\n")
}

# An error generated by stop() can be caught
foo()

# ...which is not possible when using abort()
bar()

# This expression is never reached
cat("This line will never be outputted.\n")


## End(Not run)

R.oo documentation built on Aug. 26, 2020, 5:13 p.m.