The display of errors depends on whether they're expected (i.e.
chunk option error = TRUE
) or unexpected:
Expected errors are controlled by the global option
"rlang_backtrace_on_error_report"
(note the _report
suffix).
The default is "none"
so that your expected errors don't
include a reminder to run rlang::last_error()
. Customise this
option if you want to demonstrate what the error backtrace will
look like.
You can also use last_error()
to display the trace like you
would in your session, but it currently only works in the next
chunk.
Unexpected errors are controlled by the global option
"rlang_backtrace_on_error"
. The default is "branch"
so you'll
see a simplified backtrace in the knitr output to help you figure
out what went wrong.
When knitr is running (as determined by the knitr.in.progress
global option), the default top environment for backtraces is set
to the chunk environment knitr::knit_global()
. This ensures that
the part of the call stack belonging to knitr does not end up in
backtraces. If needed, you can override this by setting the
rlang_trace_top_env
global option.