Skip to content
Back to formatted view

Raw Message

Message-ID: <k4l870p6eqfisbutc4e5a6a0it2gebufeu@4ax.com>
Date: 2004-04-07T21:38:52Z
From: Duncan Murdoch
Subject: More user-friendly error message needed.
In-Reply-To: <1081364866.2239.4.camel@dhcp9931.dhcp.unc.edu>

(Moved from r-help to r-devel).

On 07 Apr 2004 15:07:49 -0400, Shin <sdhyok@email.unc.edu> 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.

There are several places this could be fixed.  When you use x$z, the
code for $ could give an error message or a warning; instead it
returns NULL with no error or warning.  Changing this would probably
be dangerous:  I'd guess there's code out there that relies on getting
a NULL back from a construction like that.  But maybe we should change
that in 2.0?

Then plot(NULL) is called, which eventually results in the message you
saw.  That could be easily fixed:  plot.default could have 

if (is.null(x)) stop("x is NULL")

I can't think of a reason why this would cause trouble.  However, if
you had something like

plot(x$y, x$z)

the error wouldn't be detected.

Finally, the actual error message comes from a bug in the xy.coords
code: it has 

           y <- x
            x <- 1:length(x)

for the case where there is a NULL y supplied, and this is wrong:  it
should be x <- seq(along=x).  Making just this fix gives a fairly
inscrutable error message:

Error in plot.window(xlim, ylim, log, asp, ...) : 
        need finite xlim values
In addition: Warning messages: 
1: no finite arguments to min; returning Inf 
2: no finite arguments to max; returning -Inf 
3: no finite arguments to min; returning Inf 
4: no finite arguments to max; returning -Inf 

but this might be easier to figure out than the original one.

Duncan Murdoch