EVOLUTION-MANAGER
Edit File: stacktrace.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Stack trace manipulation functions</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for stacktrace {shiny}"><tr><td>stacktrace {shiny}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Stack trace manipulation functions</h2> <h3>Description</h3> <p>Advanced (borderline internal) functions for capturing, printing, and manipulating stack traces. </p> <h3>Usage</h3> <pre> captureStackTraces(expr) withLogErrors( expr, full = getOption("shiny.fullstacktrace", FALSE), offset = getOption("shiny.stacktraceoffset", TRUE) ) printError( cond, full = getOption("shiny.fullstacktrace", FALSE), offset = getOption("shiny.stacktraceoffset", TRUE) ) printStackTrace( cond, full = getOption("shiny.fullstacktrace", FALSE), offset = getOption("shiny.stacktraceoffset", TRUE) ) extractStackTrace( calls, full = getOption("shiny.fullstacktrace", FALSE), offset = getOption("shiny.stacktraceoffset", TRUE) ) formatStackTrace( calls, indent = " ", full = getOption("shiny.fullstacktrace", FALSE), offset = getOption("shiny.stacktraceoffset", TRUE) ) conditionStackTrace(cond) conditionStackTrace(cond) <- value ..stacktraceon..(expr) ..stacktraceoff..(expr) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>expr</code></td> <td> <p>The expression to wrap.</p> </td></tr> <tr valign="top"><td><code>full</code></td> <td> <p>If <code>TRUE</code>, then every element of <code>sys.calls()</code> will be included in the stack trace. By default (<code>FALSE</code>), calls that Shiny deems uninteresting will be hidden.</p> </td></tr> <tr valign="top"><td><code>offset</code></td> <td> <p>If <code>TRUE</code> (the default), srcrefs will be reassigned from the calls they originated from, to the destinations of those calls. If you're used to stack traces from other languages, this feels more intuitive, as the definition of the function indicated in the call and the location specified by the srcref match up. If <code>FALSE</code>, srcrefs will be left alone (traditional R treatment where the srcref is of the callsite).</p> </td></tr> <tr valign="top"><td><code>cond</code></td> <td> <p>A condition that may have previously been annotated by <code>captureStackTraces</code> (or <code>withLogErrors</code>).</p> </td></tr> <tr valign="top"><td><code>indent</code></td> <td> <p>A string to prefix every line of the stack trace.</p> </td></tr> <tr valign="top"><td><code>value</code></td> <td> <p>The stack trace value to assign to the condition.</p> </td></tr> </table> <h3>Details</h3> <p><code>captureStackTraces</code> runs the given <code>expr</code> and if any <em>uncaught</em> errors occur, annotates them with stack trace info for use by <code>printError</code> and <code>printStackTrace</code>. It is not necessary to use <code>captureStackTraces</code> around the same expression as <code>withLogErrors</code>, as the latter includes a call to the former. Note that if <code>expr</code> contains calls (either directly or indirectly) to <code>try</code>, or <code>tryCatch</code> with an error handler, stack traces therein cannot be captured unless another <code>captureStackTraces</code> call is inserted in the interior of the <code>try</code> or <code>tryCatch</code>. This is because these calls catch the error and prevent it from traveling up to the condition handler installed by <code>captureStackTraces</code>. </p> <p><code>withLogErrors</code> captures stack traces and logs errors that occur in <code>expr</code>, but does allow errors to propagate beyond this point (i.e. it doesn't catch the error). The same caveats that apply to <code>captureStackTraces</code> with regard to <code>try</code>/<code>tryCatch</code> apply to <code>withLogErrors</code>. </p> <p><code>printError</code> prints the error and stack trace (if any) using <code>warning(immediate.=TRUE)</code>. <code>printStackTrace</code> prints the stack trace only. </p> <p><code>extractStackTrace</code> takes a list of calls (e.g. as returned from <code>conditionStackTrace(cond)</code>) and returns a data frame with one row for each stack frame and the columns <code>num</code> (stack frame number), <code>call</code> (a function name or similar), and <code>loc</code> (source file path and line number, if available). It was deprecated after shiny 1.0.5 because it doesn't support deep stack traces. </p> <p><code>formatStackTrace</code> is similar to <code>extractStackTrace</code>, but it returns a preformatted character vector instead of a data frame. It was deprecated after shiny 1.0.5 because it doesn't support deep stack traces. </p> <p><code>conditionStackTrace</code> and <code style="white-space: pre;">conditionStackTrace<-</code> are accessor functions for getting/setting stack traces on conditions. </p> <p>The two functions <code>..stacktraceon..</code> and <code>..stacktraceoff..</code> have no runtime behavior during normal execution; they exist only to create artifacts on the stack trace (sys.call()) that instruct the stack trace pretty printer what parts of the stack trace are interesting or not. The initial state is 1 and we walk from the outermost call inwards. Each ..stacktraceoff.. decrements the state by one, and each ..stacktraceon.. increments the state by one. Any stack trace frame whose value is less than 1 is hidden, and finally, the ..stacktraceon.. and ..stacktraceoff.. calls themselves are hidden too. </p> <h3>Value</h3> <p><code>printError</code> and <code>printStackTrace</code> return <code>invisible()</code>. The other functions pass through the results of <code>expr</code>. </p> <h3>Examples</h3> <pre> # Keeps tryCatch and withVisible related calls off the # pretty-printed stack trace visibleFunction1 <- function() { stop("Kaboom!") } visibleFunction2 <- function() { visibleFunction1() } hiddenFunction <- function(expr) { expr } # An example without ..stacktraceon/off.. manipulation. # The outer "try" is just to prevent example() from stopping. try({ # The withLogErrors call ensures that stack traces are captured # and that errors that bubble up are logged using warning(). withLogErrors({ # tryCatch and withVisible are just here to add some noise to # the stack trace. tryCatch( withVisible({ hiddenFunction(visibleFunction2()) }) ) }) }) # Now the same example, but with ..stacktraceon/off.. to hide some # of the less-interesting bits (tryCatch and withVisible). ..stacktraceoff..({ try({ withLogErrors({ tryCatch( withVisible( hiddenFunction( ..stacktraceon..(visibleFunction2()) ) ) ) }) }) }) </pre> <hr /><div style="text-align: center;">[Package <em>shiny</em> version 1.5.0 <a href="00Index.html">Index</a>]</div> </body></html>