tags:

views:

427

answers:

3

Hi everybody,

After learning R about 9 months ago, I am finally graduating from debugging by using print() statements every other line. I am now a pretty constant user of browser() and debug(). I have recently become aware of a few more tools: traceback(), trace(), and recover().

Does anybody have advice on when (and how) to use these?

+7  A: 

The best walkthrough I've seen so far is:

http://www.biostat.jhsph.edu/%7Erpeng/docs/R-debug-tools.pdf

Anybody agree/disagree?

Christopher DuBois
Very thorough guide- describes essential tools included in R core: debug(),traceback() and recover().
Sharpie
+2  A: 

Mark Bravington's debugger which is available as the package debug on CRAN is very good and pretty straight forward.

library(debug);
mtrace(myfunction);
myfunction(a,b);
#... debugging, can query objects, step, skip, run, breakpoints etc..
qqq(); # quit the debugger only
mtrace.off(); # turn off debugging

The code pops up in a highlighted Tk window so you can see what's going on and, of course you can call another mtrace() while in a different function.

HTH

David Lawrence Miller
+2  A: 

Check out Duncan Murdoch's page on Debugging in R

Rob Hyndman