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")