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"
>
Hi, Tony:
Are you familiar with the 'debug' command? I agree that more
informative error messages and 'traceback' would be nice, but I've
found
the 'debug' facility quite useful. [I even sometimes prepare a shell of
a function 'fn', then say debug(fn) and fn(), and complete writing the
function in its native environment where I can more easily check what
each step does.] I've heard that 'debug' does not work will with S4
class generics, but I have not so far had to deal with that. {There is
also a 'debug' package, which is completely separate from the debug
command in the 'base' package. I've heard that it has more
extensive
capabilities, but I've never used it.}
I suspect you may already know 'debug', but for those who
don't, I
think it's worth noting its utility for this kind of thing.
Hope this helps.
Spencer Graves
Tony Plate wrote:> 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"
> >
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
It is not clear to me what you want here. Errors are tagged by a 'call', and f(1:3) is the innermost 'call' (special primitives do not set a context and so do not count if you consider '[' to be a function). The message could tell you what the type was, but it does not and we have lost the pool of active contributors we once had to submit tested patches for things like that. On Mon, 7 May 2007, Tony Plate wrote:> 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" > > > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Reasonably Related Threads
- question on docs for delayedAssign and substitute
- should Sys.glob() cope with a UNC windows path beginning with backslashes?
- bug in partial matching of attribute names
- how to control which version of a package library() installs?
- problem with 'install.packages'