Learn R Programming

tryCatchLog (version 1.0.2)

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

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 added in the form \<file name\>#\<line number\>: executed R expression (call)

Usage

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 1000

Value

A list of strings (one for each call)

Details

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 base 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

See Also

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

Examples

Run this code
# NOT RUN {
limitedLabelsCompact(sys.calls(), TRUE)
# }

Run the code above in your browser using DataLab