entrace {rlang}R Documentation

Add backtrace from error handler

Description

entrace() is a low level function. See global_entrace() for a user-friendly way of enriching errors and other conditions from your RProfile.

entrace() also works as an option(error = ) handler for compatibility with versions of R older than 4.0.

When used as calling handler, rlang trims the handler invokation context from the backtrace.

Usage

entrace(cnd, ..., top = NULL, bottom = NULL)

cnd_entrace(cnd, ..., top = NULL, bottom = NULL)

Arguments

cnd

When entrace() is used as a calling handler, cnd is the condition to handle.

...

Unused. These dots are for future extensions.

top

The first frame environment to be included in the backtrace. This becomes the top of the backtrace tree and represents the oldest call in the backtrace.

This is needed in particular when you call trace_back() indirectly or from a larger context, for example in tests or inside an RMarkdown document where you don't want all of the knitr evaluation mechanisms to appear in the backtrace.

If not supplied, the rlang_trace_top_env global option is consulted. This makes it possible to trim the embedding context for all backtraces created while the option is set. If knitr is in progress, the default value for this option is knitr::knit_global() so that the knitr context is trimmed out of backtraces.

bottom

The last frame environment to be included in the backtrace. This becomes the rightmost leaf of the backtrace tree and represents the youngest call in the backtrace.

Set this when you would like to capture a backtrace without the capture context.

Can also be an integer that will be passed to caller_env().

See Also

global_entrace() for configuring errors with entrace(). cnd_entrace() to manually add a backtrace to a condition.

Examples

Run examples

quote({  # Not run

# Set `entrace()` globally in your RProfile
globalCallingHandlers(error = rlang::entrace)

# On older R versions which don't feature `globalCallingHandlers`,
# set the error handler like this:
options(error = rlang::entrace)

})

[Package rlang version 1.1.4 Index]