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()
is meant to be used as a global handler. It enriches conditions with a backtrace. Errors are saved tolast_error()
and rethrown immediately. Messages and warnings are recorded intolast_messages()
andlast_warnings()
and let through. -
cnd_entrace()
adds a backtrace to a condition object, without any other effect. It should be called from a condition handler.
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 |
... |
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 If not supplied, the |
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 |
See Also
global_entrace()
for configuring errors with
entrace()
. cnd_entrace()
to manually add a backtrace to a
condition.
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)
})