By default 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 message. It can also be used to print the current stack or arbitrary lists of deparsed calls. .traceback() now returns the above call stack (and traceback(x, *) can be regarded as convenience function for printing the result of .traceback(x)).
traceback(x = NULL, max.lines = getOption("deparse.max.lines"))
.traceback(x = NULL)
| Parameter | Description |
|---|---|
x |
NULL (default, meaning .Traceback), or an integer count of calls to skip in the current stack, or a list or pairlist of deparsed calls. See the details. |
max.lines |
The maximum number of lines to be printed per call. The default is unlimited. |
# NOT RUN {
foo <- function(x) { print(1); bar(2) }
bar <- function(x) { x + a.variable.which.does.not.exist }
# }
# NOT RUN {
foo(2) # gives a strange error
traceback()
# }
# NOT RUN {
<!-- %dont -->
# }
# 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))
# }