[R] getting informative error messages

Tony Plate tplate at acm.org
Mon May 7 23:32:42 CEST 2007


Certain errors seem to generate messages that are less informative than 
most -- they just tell you which function an error happened in, but 
don't indicate which line or expression the error occurred in.

Here's a toy example:

 > f <- function(x) {a <- 1; y <- x[list(1:3)]; b <- 2; return(y)}
 > options(error=NULL)
 > f(1:3)
Error in f(1:3) : invalid subscript type
 > traceback()
1: f(1:3)
 >

In this function, it's clear that the error is in subscripting 'x', but 
it's not always so immediately obvious in lengthier functions.

Is there anything I can do to get a more informative error message in 
this type of situation?  I couldn't find any help in the section 
"Debugging R Code" in "R-exts" (or anything at all relevant in "R-intro").

(Different values for options(error=...) and different formatting of the 
function made no difference.)

-- Tony Plate

 > sessionInfo()
R version 2.5.0 (2007-04-23)
i386-pc-mingw32

locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United 
States.1252;LC_MONETARY=English_United 
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252

attached base packages:
[1] "stats"     "graphics"  "grDevices" "utils"     "datasets"  "methods"
[7] "base"

other attached packages:
tap.misc
    "1.0"
 >



More information about the R-help mailing list