limitedLabelsCompact: Convert a call stack into a list of printable strings

Description Usage Arguments Details Value See Also Examples

View source: R/limited_Labels_Compact.R

Description

Converts a call stack into a list of printable strings ("labels") with a limited length per call. If source code references are available they are also printed in the stack trace using this notation: <file name>#<line number>: executed R expression (call)

Usage

1
2
3
4
5
limitedLabelsCompact(
  value,
  compact = FALSE,
  maxwidth = getOption("width") - 5L
)

Arguments

value

a list of calls ("call.stack") generated by sys.calls

compact

if TRUE only calls that contain a source code reference (attribute "srcref") are returned (plus always the first call); if FALSE all calls will be returned.

maxwidth

Maximum number of characters per call in the return value (longer strings will be cutted). Must be between 40 and 2000 (until version 1.2.2: 1000)

Details

By default the maximum number of source code rows that are printed per call in the full stack trace is 10. You can change this via the option tryCatchLog.max.lines.per.call (see example).

R does track source code references only if you set the option "keep.source" to TRUE via options(keep.source = TRUE). Without this option this function cannot enrich source code references. If you use Rscript to start a non-interactive R script as batch job you have to set this option since it is FALSE by default. You can add this option to your .Rprofile file or use a startup R script that sets this option and sources your actual R script then.

This function is based on the undocumented limitedLabels function of the base package. The source code can be viewed by entering limitedLabels in the R console. The attributes required to add source file names and line numbers to the calls (srcref and srcfile) and how they are created internally are explained in this article: https://journal.r-project.org/archive/2010-2/RJournal_2010-2_Murdoch.pdf

Value

A list of strings (one for each call). If compact is TRUE at the last call is returned even if it does not contain a source code reference.

See Also

sys.calls, tryCatchLog, get.pretty.call.stack

Examples

1
2
options(tryCatchLog.max.lines.per.call = 30)
limitedLabelsCompact(sys.calls(), TRUE)

tryCatchLog documentation built on Oct. 25, 2021, 9:08 a.m.