[R] Line numbers with errors and warnings?

Steve Lianoglou mailinglist.honeypot at gmail.com
Sun Dec 2 12:02:41 CET 2012


Hi,

On Sun, Dec 2, 2012 at 12:31 AM, Worik R <worikr at gmail.com> wrote:
> What I mean is how do I get the R compilation or execution process to spit
> out a line number with errors and warnings?

As Duncan mentioned already, you can't *always* get a line number. You
can, however, usually get enough context around the failing call for
you to be able to smoke the problem out.

> option(error=browser) is a help.  But it still does not say what piece of
> code caused the error.

I typically run with a slightly different setting:

R> options(error=utils:::dump.frames)

Whenever my script throws an error, after I'm done cursing at it I
then wonder where this error happened, so I call:

R> traceback()

And you'll see the details of the stack that just blew up, starting
(or ending, can't remember) with the call itself, then the parent
call, and its parent, etc. all the way up to the top most call (likely
the line in your script itself).

If that's not enough information for me to figure out how to fix the
code in my script, I'll then call:

R> debugger()

and this will then give me (more or less) the same information that
`traceback` showed (but in reverse order (which is why I never
remember the order of traceback)) and you are asked at what point
you'd like to enter the exploded wreckage to explore (via picking a
number) ... this way you can poke at the local variables until you see
what went wrong.

Your error:

Error in `[.xts`(x, xsubset) : subscript out of bounds

Is suggesting that you are trying to index an `xts` object with an
illegal value -- can you find the part in your code that's trying to
do this in your own script? You can put a call to `browser()` before
that part and explore the value of the subscript vs. the length of
your xts object to see what the problem is.

If you can't find this point, then take the traceback/debugger route.

> This is costing me a lot of time chasing down errors in mine and others
> code...

... which is typical when your wading in uncharted territory. As you
get a better feel of how to resolve these issues, your time-to-fix
these things will get better, so ... stay strong.

-steve

-- 
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact




More information about the R-help mailing list