Skip to content
Prev 312713 / 398506 Next

Line numbers with errors and warnings?

Similar to Duncan's example, if you have a script "test.R" which looks like so:

==== start script =====
a1 <- 1:10
a2 <- 101:122
plot(a1, a1)
plot(a1, a2)
==== end script ======

You can source it one way:

R> source('test.R', keep.source=TRUE)
Error in xy.coords(x, y, xlabel, ylabel, log) :
  'x' and 'y' lengths differ
R> traceback()
8: stop("'x' and 'y' lengths differ")
7: xy.coords(x, y, xlabel, ylabel, log)
6: plot.default(a1, a2)
5: plot(a1, a2) at test.R#4  ### <- Error is on line 4
4: eval(expr, envir, enclos)
3: eval(ei, envir)
2: withVisible(eval(ei, envir))
1: source("test.R", keep.source = TRUE)

If you `source("test.R", keep.source=FALSE)`, you will see that the
line number is not reported.

Also:

R> library(devtools)
R> options(keep.source=TRUE)
R> install_github("BadPackage", "lianos")
R> plot.me(1:10)
Error in xy.coords(x, y, xlabel, ylabel, log) :
  'x' and 'y' lengths differ
R> traceback()
5: stop("'x' and 'y' lengths differ")
4: xy.coords(x, y, xlabel, ylabel, log)
3: plot.default(x, c(x, 0), pch = 16)
2: plot(x, c(x, 0), pch = 16) at test.R#4  #### <- BAM
1: plot.me(1:10)

HTH,
-steve
On Sun, Dec 2, 2012 at 5:08 PM, Duncan Murdoch <murdoch.duncan at gmail.com> wrote: