traceback.Rd 2.92 KB
 Radford Neal committed May 18, 2013 1 2 % File src/library/base/man/traceback.Rd % Part of the R package, http://www.R-project.org  Radford Neal committed Aug 26, 2016 3 % Copyright 1995-2007 R Core Team  Radford Neal committed May 18, 2013 4 5 6 7 8 9 10 11 12 13 % Distributed under GPL 2 or later \name{traceback} \alias{traceback} \alias{.Traceback} \title{Print Call Stacks} \description{ By default \code{traceback()} prints the call stack of the last uncaught error, i.e., the sequence of calls that lead to the error. This is useful when an error occurs with an unidentifiable error  Radford Neal committed May 18, 2013 14 15  message. It can also be used to print the current stack or arbitrary lists of deparsed calls.  Radford Neal committed May 18, 2013 16 17 18 19 20 } \usage{ traceback(x = NULL, max.lines = getOption("deparse.max.lines")) } \arguments{  Radford Neal committed May 18, 2013 21 22 23  \item{x}{\code{NULL} (default, meaning \code{.Traceback}), or an integer count of calls to skip in the current stack, or a list or pairlist of deparsed calls. See the details.}  Radford Neal committed May 18, 2013 24 25 26 27  \item{max.lines}{The maximum number of lines to be printed \emph{per call}. The default is unlimited.} } \details{  Radford Neal committed May 18, 2013 28 29 30 31 32 33 34 35  The default display is of the stack of the last uncaught error as stored as a list of deparsed calls in \code{.Traceback}, which \code{traceback} prints in a user-friendly format. The stack of deparsed calls always contains all function calls and all foreign function calls (such as \code{\link{.Call}}): if profiling is in progress it will include calls to some primitive functions. (Calls to builtins are included, but not to specials.)  Radford Neal committed May 18, 2013 36 37 38 39  Errors which are caught \emph{via} \code{\link{try}} or \code{\link{tryCatch}} do not generate a traceback, so what is printed is the call sequence for the last uncaught error, and not necessarily for the last error.  Radford Neal committed May 18, 2013 40 41 42 43 44 45 46 47 48  If \code{x} is numeric, then the current stack is printed, skipping \code{x} entries at the top of the stack. For example, \code{options(error=function() traceback(2))} will print the stack at the time of the error, skipping the call to \code{traceback()} and the error function that called it. Otherwise, \code{x} is assumed to be a list or pairlist of deparsed calls and will be displayed in the same way.  Radford Neal committed May 18, 2013 49 50 } \value{  Radford Neal committed May 18, 2013 51 52 53 54 55  \code{traceback()} prints the deparsed call stack deepest call first, and returns it invisibly. The calls may print on more than one line, and the first line for each call is labelled by the frame number. The number of lines printed per call can be limited via \code{max.lines}.  Radford Neal committed May 18, 2013 56 57 58 } \section{Warning}{ It is undocumented where \code{.Traceback} is stored nor that it is  Radford Neal committed May 18, 2013 59  visible, and this is subject to change.  Radford Neal committed May 18, 2013 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 } \references{ Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) \emph{The New S Language}. Wadsworth & Brooks/Cole. } \examples{ foo <- function(x) { print(1); bar(2) } bar <- function(x) { x + a.variable.which.does.not.exist } \dontrun{ foo(2) # gives a strange error traceback()} ## 2: bar(2) ## 1: foo(2) bar ## Ah, this is the culprit ...  Radford Neal committed May 18, 2013 76 77 78  ## This will print the stack trace at the time of the error. options(error=function() traceback(2))  Radford Neal committed May 18, 2013 79 80 } \keyword{programming}