Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

rst_abort

Jump to the abort restart


Description

Questioning lifecycle

The abort restart is the only restart that is established at top level. It is used by R as a top-level target, most notably when an error is issued (see abort()) that no handler is able to deal with (see with_handlers()).

Usage

rst_abort()

Life cycle

All the restart functions are in the questioning stage. It is not clear yet whether we want to recommend restarts as a style of programming in R.

See Also

Examples

# The `abort` restart is a bit special in that it is always
# registered in a R session. You will always find it on the restart
# stack because it is established at top level:
rst_list()

# You can use the `above` restart to jump to top level without
# signalling an error:
## Not run: 
fn <- function() {
  cat("aborting...\n")
  rst_abort()
  cat("This is never called\n")
}
{
  fn()
  cat("This is never called\n")
}

## End(Not run)

# The `above` restart is the target that R uses to jump to top
# level when critical errors are signalled:
## Not run: 
{
  abort("error")
  cat("This is never called\n")
}

## End(Not run)

# If another `abort` restart is specified, errors are signalled as
# usual but then control flow resumes with from the new restart:
## Not run: 
out <- NULL
{
  out <- with_restarts(abort("error"), abort = function() "restart!")
  cat("This is called\n")
}
cat("`out` has now become:", out, "\n")

## End(Not run)

rlang

Functions for Base Types and Core R and 'Tidyverse' Features

v0.4.11
MIT + file LICENSE
Authors
Lionel Henry [aut, cre], Hadley Wickham [aut], mikefc [cph] (Hash implementation based on Mike's xxhashlite), Yann Collet [cph] (Author of the embedded xxHash library), RStudio [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.