format_trace: Pretty-print a captured call trace

View source: R/log.R

format_traceR Documentation

Pretty-print a captured call trace

Description

Formats the ⁠$calls⁠ carried by an rtemis_error condition (see abort()) as a numbered, one-line-per-frame string. Most-recent frame at the bottom, matching base R's traceback() convention. Each frame is deparsed with a single-line cap so long calls stay readable; no styling is applied, so the output is safe for any sink (terminal, JSON, HTML).

Usage

format_trace(trace, max_width = 80L)

Arguments

trace

pairlist of calls, as captured by abort() on cond$calls. Passing the condition itself also works - the calls are extracted via cond[["calls"]], falling back to an rlang trace on cond[["trace"]].

max_width

Integer: Max characters per deparsed line. Longer calls are truncated with a trailing ellipsis. Ignored for rlang traces, which rlang formats itself.

Details

Conditions from packages built on rlang::abort() carry their stack as an rlang trace object on ⁠$trace⁠ rather than on ⁠$calls⁠. Those are passed to rlang's own formatter, so the result is rlang's tree layout and max_width does not apply; any ANSI styling is stripped.

Value

Character scalar with one frame per ⁠\n⁠-separated line, newest frame last. "" if the trace is empty or NULL.

Author(s)

EDG

Examples

## Not run: 
cond <- tryCatch(
  check_numeric("oops"),
  error = identity
)
cat(format_trace(cond), "\n")

## End(Not run)

rtemis.core documentation built on Sept. 20, 2026, 9:06 a.m.