From QERM Wiki
Revision as of 23:38, 17 June 2009 by Chloe (Talk | contribs)
Jump to: navigation, search

Interactive Debugging in R

Often times when we write our own functions, or use other functions in various packages, the error messages can sometimes get confusing. While good programming practice and patience are keys to solving these problems, R also has some other tools that can be used to make the debugging process, which is critical in any programming assignment, as engaging and smooth (and even fun!) as possible.

The most useful debugging functions are

  • traceback
  • debug
  • trace
  • options(error=recover)

Pdf10.png Here is a very helpful reference on interactive debugging by Roger Peng, UCLA.


Keep in mind the 2 rules of performance optimization, "The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet." by Michael Jackson, and these basic principles. If you are going to optimize your code, it's critical to profile it first, as our intuition as to what is slow is often wrong. Rprof is a package in R that lets you profile a function.

Ways to use Rprof's output

Personal tools