[R] Line numbers in error messages
p.connolly at hortresearch.co.nz
Tue Apr 13 02:10:46 CEST 2004
On Mon, 12-Apr-2004 at 03:20PM -0700, Webb Sprague wrote:
|> Hi Patrick,
|> >It's very simple using a browser() line in your function somewhere you
|> >know your code's OK, then run line by line.
|> The problem is that sometimes you have code of a few hundred lines, to
|> which you have added a strange little line that craps out because of
|> some silly mistake that would be apparent if you knew which line to look
|> at. However.... you don't want to start inserting browser statements
|> inside the code, hoping to get close, you just want to know what line
|> caused the issue.
Many things might be better if they were different, but they aren't.
Just count your blessings you're using something as easy to delve into
as R code.
I don't find it difficult to work out where the problem is. The
traceback() stack gives an idea which line of your function had a
problem. I put a browser just before that, and check if objects are
what I thought they'd be.
Sometimes it might involve adding a browser to a called function, and
sometimes the problem is a long way back. (I've had lots of
experience doing this sort of thing.)
Even if one does have to go through line by line, unless you have lots
of long calculations, it's very quick to move through scores of
lines of code using C-c C-n. It's even possible to run a number of
lines in one go to work out which bunch the problem is in, then you
can look further within that bunch if it's the one that produces an
error (it won't have crashed).
I've found it much quicker to find errors in R code than I do in perl code.
|> I already use ESS. If it would give line numbers, my life would be perfect!
I think you'd then find something else that wasn't. :-)
|> Is there something about debugging in S/R that I am missing? I don't
|> want to have to run a debugger except when there is a real problem, not
|> just some silliness.
In my experience, it silliness 99% of the time.
Ph: +64-9 815 4200 x 7188
I have the world`s largest collection of seashells. I keep it on all
the beaches of the world ... Perhaps you`ve seen it. ---Steven Wright
More information about the R-help