Skip to content

debugging functions in R

7 messages · Eran Eidinger, Liviu Andronic, Justin Haynes +3 more

#
On Wed, Aug 24, 2011 at 4:20 PM, Eran Eidinger <eran at taykey.com> wrote:
My solution when I run into mysteries like this is to put 'browser()' in the
function just before or after the line of interest. The magnitude and direction
of my stupidity usually become clear quickly.
   -- Patrick Burns
      R-help (February 2006)


Use browser() to inspect the environment and execute the code one step
at a time.
Liviu

  
    
  
#
Also check out the 'debug' package
On Wed, Aug 24, 2011 at 10:59 AM, Eran Eidinger <eran at taykey.com> wrote:

  
    
1 day later
#
On 11-08-24 10:20 AM, Eran Eidinger wrote:
The trace() function does that.  setBreakpoint() is a front end for it. 
  One current limitation is that it only allows one breakpoint per 
function; that may change soon.
Write a package.  It is much easier than it looks at first.  Start with 
package.skeleton, and follow the instructions from there.
Functions always have a local context for writing.  There's no simple 
way to create a local context for reading.

Duncan Murdoch
#
See also the debug function, which allows you to walk through a 
function line by line.


       I also concur with Duncan's recommendation to try the R package 
system.  I'm an author of one of two contributed documents available 
from CRAN -> Documentation:  Contributed -> "Creating R Packages".  When 
I started writing R packages, I felt it tripled my software development 
productivity overnight by making it easier to find bugs and keep track 
of what I had done -- not to mention making it much easier to share my 
work with others.


       Hope this helps.
       Spencer
On 8/25/2011 11:23 AM, Duncan Murdoch wrote: