| traceback | R Documentation |
By defaulttraceback() prints the call stack of the lastuncaught error, i.e., the sequence of calls that lead to the error.This is useful when an error occurs with an unidentifiable errormessage. It can also be used to print the current stack orarbitrary lists of calls.
.traceback() nowreturns the above call stack (andtraceback(x, *) can be regarded as convenience function forprinting the result of.traceback(x)).
traceback(x = NULL, max.lines = getOption("traceback.max.lines", getOption("deparse.max.lines", -1L))).traceback(x = NULL, max.lines = getOption("traceback.max.lines", getOption("deparse.max.lines", -1L)))x |
|
max.lines | a number, the maximum number of lines to be printedper call. The default is unlimited. Applies only when |
The default display is of the stack of the last uncaught error asstored as a list ofcalls in.Traceback, whichtraceback prints in a user-friendly format. The stack ofcalls always contains all function calls and all foreignfunction calls (such as.Call): if profiling is inprogress it will include calls to some primitive functions. (Callsto builtins are included, but not to specials.)
Errors which are caughtviatry ortryCatch do not generate a traceback, so what is printedis the call sequence for the last uncaught error, and not necessarilyfor the last error.
Ifx is numeric, then the current stack is printed, skippingx entries at the top of the stack. For example,options(error = function() traceback(3)) will print the stackat the time of the error, skipping the call totraceback() and.traceback()and the error function that called it.
Otherwise,x is assumed to be a list or pairlist of calls ordeparsed calls and will be displayed in the same way.
.traceback() and by extensiontraceback() may triggerdeparsing ofcalls. This is an expensive operationfor large calls so it may be advisable to setmax.linesto a reasonable value when such calls are on the call stack.
.traceback() returns the deparsed call stack deepest callfirst as a list or pairlist. The number of lines deparsed fromthe call can be limited viamax.lines. Calls for whichmax.lines results in truncated output will gain a"truncated" attribute.
traceback() formats, prints, and returns the call stackproduced by.traceback() invisibly.
It is undocumented where.Traceback is stored nor that it isvisible, and this is subject to change. As ofR 4.0.0.Traceback contains thecalls as languageobjects, whereas previously these calls were deparsed.
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)The New S Language.Wadsworth & Brooks/Cole.
foo <- function(x) { print(1); bar(2) }bar <- function(x) { x + a.variable.which.does.not.exist }## Not run: foo(2) # gives a strange errortraceback()## End(Not run)## 2: bar(2)## 1: foo(2)bar## Ah, this is the culprit ...## This will print the stack trace at the time of the error.options(error = function() traceback(3))Add the following code to your website.
For more information on customizing the embed code, readEmbedding Snippets.