[R] More user-friendly error message needed.
Tony Plate
tplate at blackmesacapital.com
Wed Apr 7 21:35:31 CEST 2004
It's actually not that easy to provide the meaningful kind of error message
you are asking for. (Though it would be nice.)
Consider what happens in the case you give:
(1) The argument of plot() of evaluated, and has the value NULL
(2) plot() is called with a single argument, which is NULL
All the information available inside plot() is that its argument has the
value NULL (without getting into meta programming). However, it would be
possible for plot(), or xy.coords(), to print a more meaningful error
message like "called with NULL value for x". This disadvantage of doing
this is that if you do it everywhere, a considerable volume of the code
becomes tests and error messages, which can make the code less readable and
more prone to errors (because of the possibility that some of the tests are
buggy themselves). The weak type checking in the S language exacerbates
these problems. As it currently is, many functions are simple and concise,
but provide very cryptic error messages when something goes wrong. This is
the tradeoff.
One might argue that x$z should cause an error, but it is a
long-established behavior that the "$" operator returns NULL when the list
element does not exist or is not uniquely identified (this might even be in
the written definition of the S language).
It might be an interesting CS grad student project to build a system that
matches cryptic error messages and stack traces against a library of common
errors in order to provide less cryptic error messages.
-- Tony Plate
At Wednesday 01:07 PM 4/7/2004, Shin wrote:
>When I tried the following commands, I got a strange message.
>
>
> > x<-data.frame(y=c(1:10))
> > plot(x$z)
>Error in xy.coords(x, y, xlabel, ylabel, log) :
> x and y lengths differ
>
>"The data frame, x, does not have a field named z."
>may be better user-friendly message for this kind of common error.
>
>
>Daehyok Shin
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
More information about the R-help
mailing list