[R] Line numbers with errors and warnings?

Duncan Murdoch murdoch.duncan at gmail.com
Sun Dec 2 15:02:03 CET 2012


On 12-12-02 12:31 AM, Worik R 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?
>
> I should not have mentioned ESS, that is a distraction.

I think ESS is not a distraction here, it is the cause of the problem. 
If you source() your code, R will (by default) record line numbers.  ESS 
apparently doesn't send code to R using source().  (Or perhaps it does, 
and you aren't looking in the right place for it?)

For example, in Windows, if I put this code into the clipboard:

f <- function() {
   stop("this is the error")
}

g <- function() {
   f()
}

g()

then run source("clipboard") followed by traceback(), this is what I see:

 > source("clipboard")
Error in f() (from clipboard#2) : this is the error
 > traceback()
7: stop("this is the error") at clipboard#2
6: f() at clipboard#6
5: g() at clipboard#9
4: eval(expr, envir, enclos)
3: eval(ei, envir)
2: withVisible(eval(ei, envir))
1: source("clipboard")

You can ignore entries 1 to 4; they are part of source().  Entries 5, 6, 
and 7 each tell the line of the script where they were parsed.

Duncan Murdoch

>
> option(error=browser) is a help.  But it still does not say what piece
> of code caused the error.
>
> This is costing me a lot of time chasing down errors in mine and others
> code...
>
> Worik
>
>
> On Sat, Dec 1, 2012 at 1:47 PM, Duncan Murdoch <murdoch.duncan at gmail.com
> <mailto:murdoch.duncan at gmail.com>> wrote:
>
>     On 12-11-30 7:15 PM, Worik R wrote:
>
>         How?
>
>         This is a script I am running under ess on Emacs
>
>
>     I've never used ESS.  You'll need to ask someone on the ESS list.
>
>     Duncan Murdoch
>
>         (Useful information optuion(error=recover)
>
>         cheers
>         Worik
>
>
>         On Sat, Dec 1, 2012 at 12:34 PM, Duncan Murdoch
>         <murdoch.duncan at gmail.com <mailto:murdoch.duncan at gmail.com>
>         <mailto:murdoch.duncan at gmail.__com
>         <mailto:murdoch.duncan at gmail.com>>> wrote:
>
>              On 12-11-30 4:22 PM, Worik R wrote:
>
>                  Is it possible to get a line number with an error report?
>
>
>              Yes, if the error occurs in code that has line number
>         information.
>              You get line number info by default if you use source().
>           If the
>              error is deeply buried in code that doesn't have the info
>         (as it may
>              be in your case), then the suggestions to use
>         options(error=recover)
>              will offer you a stack trace that shows you which high
>         level code
>              called the function reporting the problem.
>
>              Duncan Murdoch
>
>
>                  I have a long script and an error:
>
>                  Error in `[.xts`(x, xsubset) : subscript out of bounds
>
>
>                  It would be very helpful, and save a lot of time, if
>         there was some
>                  indication in the error message which line the error was.
>
>                  I can find it using binary search but that is a painful
>         process.
>
>                  cheers
>                  Worik
>
>                           [[alternative HTML version deleted]]
>
>                  __________________________________________________
>         R-help at r-project.org <mailto:R-help at r-project.org>
>         <mailto:R-help at r-project.org <mailto:R-help at r-project.org>>
>         mailing list
>         https://stat.ethz.ch/mailman/____listinfo/r-help
>         <https://stat.ethz.ch/mailman/__listinfo/r-help>
>
>                  <https://stat.ethz.ch/mailman/__listinfo/r-help
>         <https://stat.ethz.ch/mailman/listinfo/r-help>>
>                  PLEASE do read the posting guide
>         http://www.R-project.org/____posting-guide.html
>         <http://www.R-project.org/__posting-guide.html>
>
>                  <http://www.R-project.org/__posting-guide.html
>         <http://www.R-project.org/posting-guide.html>>
>                  and provide commented, minimal, self-contained,
>         reproducible code.
>
>
>
>
>




More information about the R-help mailing list