traceback {base}R Documentation

Print Call Stacks


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 arbitrary lists of deparsed calls.


traceback(x = NULL)


x NULL (default), or a list or pairlist of deparsed calls.


The stack of the last uncaught error is stored as a list of deparsed calls in .Traceback, which traceback prints in a user-friendly format.

Errors which are caught via try or tryCatch do not generate a traceback, so what is printed is the call sequence for the last uncaught error, and not necessarily the last error.


traceback() returns nothing, but prints the deparsed call stack deepest call first. The calls may print on more that one line, and the first line is labelled by the frame number.


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 error
## End(Not run)
## 2: bar(2)
## 1: foo(2)
## Ah, this is the culprit ...

[Package base version 2.1.0 Index]