[R] debugging a code

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Mar 25 07:25:00 CET 2004


Using debugger() for post-mortem debugging is the best way to chase down 
the immediate cause of an error, which seems to be the issue here.

If you use debug() (which is not a `dubuger') you need to single-step
(with n), and look at values just before the line in which the error
occurs.

There are a lot of good books out there and, `Fred J.', it looks to be 
time you started reading them as you are asking a lot of questions they do 
answer.


On Wed, 24 Mar 2004, Liaw, Andy wrote:

> Well, you can insert `browser()' right above the offending line, then run
> the code again.  It will stop with the `browse>' prompt right before that
> line.  You can then check which value(s) give you the problem.
> 
> Have you tried Mark Bravington's `debug' package on CRAN?  There's an
> article on it in the most recent issue of R News.
> 
> Andy
> 
> > From: Fred J.
> > 
> > Hello
> > just learned HowTo but R, reminded me with the way
> > Perl does it but with much less on-line commands, R
> > "AFAIK" has n, c, Q and where and cann't debug outside
> > the {}. 
> > 
> > 1) is there a more versatile/flexable debugging method
> > for R?
> > 
> > I have saved 2 functions in an ASCII file "digfun".
> > "getdata" function calls "squash" function and both
> > use loops. In another file.R I have
> > 
> > source("digfun")
> > debug(getdata)
> > data <- getdata("c:/data/")
> > 
> > Browse[1]> c
> > Error in if (d[i, "V3"] == d[i + 1, "V3"] && d[i,
> > "V4"] == d[i + 1, "V4"] &&  : 
> > 	missing value where TRUE/FALSE needed
> > > traceback()
> > 2: squash(dt1)
> > 1: getdata("c:/data/")
> > > 
> > to dubug this I need to know the value of some
> > variable at this particular loop/sub-fun loop case,
> > and since the dubuger terminated by showing ">"
> > prompt, how then I am going to debug this error?

You are not even in the `debugger', sic.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list