I'm familiar with browser()
, trace()
, traceback()
, and options(error=recover)
. I'm also playing with the debug package, which looks nice. All of these put R miles ahead of other statistical packages I've worked with in terms of debugging facilities. But in comparison to compiled traditional languages, the picture seems less favorable. Which gives rise to two questions:
What debugging facility present in other languages do you miss the most?
Is it possible to add this functionality in R as it exists current, or does it require a compiler, etc.?
Edit: Eliminated my proposed entry since as was pointed out it does exist in R.
The built-in debugging tools (programs: functions) in R statistical computing environment are traceback(), debu(), browser(), trace(), and recover().
browser() function is inserted into functions to open R interactive debugger. It will stop the execution of function() and you can examine the function with the environment of itself. In debug mode, we can modify objects, look at the objects in the current environment, and also continue executing.
To debug a function which is defined inside another function, single-step through to the end of its definition, and then call debug on its name. If you want to debug a function not starting at the very beginning, use trace(..., at = *) or setBreakpoint .
If an error occurs, the easiest thing to do is to immediately call the traceback() function. This function returns the function call stack just before the error occurred so that you can see what level of function calls the error occurred.
I'm afraid you're missing some options in R. You should take a look at the functions Rprof()
and summaryRprof()
for the -in depth- profiling of code. Next to that, check also the discussion on :
What is your favorite R debugging trick?
And especially the answer of Shane. That has some more interesting tips. There's also a whole chapter on debugging in the Writing R Extensions manual.
Lastly, keep in mind that quite some debugging tools for "compiled traditional languages" are implemented in the IDE, rather than in the language itself. As R can be coupled with Eclipse and Emacs to name a few, all those debugging tools are also available for R.
reworded
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With