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

rlang_backtrace_on_error

Display backtrace on error


Description

Errors thrown with abort() automatically save a backtrace that can be inspected by calling last_error(). Optionally, you can also display the backtrace alongside the error message by setting the option rlang_backtrace_on_error to one of the following values:

  • "reminder": Display a reminder that the backtrace can be inspected by calling last_error().

  • "branch": Display a simplified backtrace.

  • "collapse": Display a collapsed backtrace tree.

  • "full": Display the full backtrace tree.

Promote base errors to rlang errors

Call options(error = rlang::entrace) to instrument base errors with rlang features. This handler does two things:

  • It saves the base error as an rlang object. This allows you to call last_error() to print the backtrace or inspect its data.

  • It prints the backtrace for the current error according to the rlang_backtrace_on_error option.

Examples

# Display a simplified backtrace on error for both base and rlang
# errors:

# options(
#   rlang_backtrace_on_error = "branch",
#   error = rlang::entrace
# )
# stop("foo")

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.