Skip to content
Prev 22193 / 63424 Next

error location

On Fri, 29 Sep 2006, Peter Stencel wrote:

            
The first step after you get an error is

   R>   traceback()


This will give a stack trace, ie, it will show the function where the 
error occurred, the function that called it, the function that called it, 
and so on all the way up.  At some point in the list there should be an 
expression that you recognize.

traceback() is often sufficient.  When it isn't, the post-mortem debugger, 
which you use by setting options(error=recover), may help.  After the 
error occurs this gives you the opportunity to run the debugger inside any 
of the functions that were executing. The debugger is basically an R 
prompt running inside the function, so you can do anything you could do in 
R. debug(f) starts the debugger whenever the function f() is called. This 
lets you get in before the error.

There is a section on debugging in the "Writing R Extensions" manual (in 
sufficiently recent versions of R).

 	-thomas