Friday, June 25, 2010

debug() in R

While I'm on a (posting) roll, here is one more useful function, one that I'm a little embarrassed about discovering only now. It's debug() function in R. You tag you favorite function, foo(), with debug(foo). The next time foo() is executed, either by itself or is called from another function, debug executes foo() line by line, and provides an interactive prompt at each step so you can check values of the variables at the current evaluation, plot things, define things, or do whatever else you want. There are some built-in commands to be used at the prompt (if you can't think of something better):

n - advance to the nextstep
c - continue to the end of the current context: e.g. to the end of the loop if within a loop or to the end of the function
Q - quit debugging

In the end you can run undebug() to stop tracking the function.

For more, see here:

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner


Blog Archive