traceCall: call stack of a function

View source: R/traceCall.R

traceCallR Documentation

call stack of a function

Description

trace the call stack e.g. for error checking and format output for do.call levels

Usage

traceCall(
  skip = 0,
  prefix = "\nCall stack: ",
  suffix = "\n",
  vigremove = TRUE,
  shiremove = TRUE,
  mesremove = TRUE
)

Arguments

skip

Number of levels to skip in sys.calls

prefix

Prefix prepended to the output character string. DEFAULT: "\nCall stack: "

suffix

Suffix appended to the end of the output. DEFAULT: "\n"

vigremove

Logical: remove call created using devtools::build_vignettes()? DEFAULT: TRUE

shiremove

Logical: remove shiny::runApp ... renderPlot? DEFAULT: TRUE

mesremove

Logical: remove call part from .makeMessage? DEFAULT: TRUE

Value

Character string with the call stack

Author(s)

Berry Boessenkool, berry-b@gmx.de, Sep 2016 + March 2017

See Also

tmessage, tryStack, checkFile for example usage

Examples

lower <- function(a, s) {warning(traceCall(s, mesremove=FALSE), "stupid berry warning: ", a+10); a}
upper <- function(b, skip=0) lower(b+5, skip)
upper(3)

# Since 2022-05-04, use tmessage / twarning / tstop instead!

upper(3, skip=1) # traceCall skips last level (R3: warning, R4.1: .makeMessage, R4.2: lapply)
upper(3, skip=6) # now the stack is empty
d <- tryStack(upper("four"), silent=TRUE)
inherits(d, "try-error")
cat(d)

lower <- function(a,...) {warning(traceCall(1, prefix="in ", suffix=": "),
                          "How to use traceCall in functions ", call.=FALSE); a}
upper(3)


berryFunctions documentation built on May 29, 2024, 4:01 a.m.