Bug 13936 - xy.coords assumes lists will have x and y components, but doesn't check
xy.coords assumes lists will have x and y components, but doesn't check
Status: RESOLVED FIXED
Product: R
Classification: Unclassified
Component: Graphics
old
All Mac OS X v10.5
: P5 normal
Assigned To: Jitterbug compatibility account
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2009-09-01 04:18 UTC by Jitterbug compatibility account
Modified: 2010-04-11 15:36 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jitterbug compatibility account 2009-09-01 04:18:18 UTC
From: richcalaway@revolution-computing.com
Full_Name: Richard  Calaway
Version: 2.9.2
OS: Mac OS X 10.5.3
Submission from: (NULL) (65.47.30.18)


Here's my sessionInfo():

> sessionInfo()
R version 2.9.2 (2009-08-24) 
i386-apple-darwin8.11.1 

locale:
en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

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


Currently, if you pass a list without x and y components to plot, you get an
error from plot.window and some warnings about "no non-missing arguments" to max
and min, and an empty graphics window:

> x <- list(fred=rnorm(10), joe=runif(10))
> plot(x)
Error in plot.window(...) : need finite 'xlim' values
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
3: In min(x) : no non-missing arguments to min; returning Inf
4: In max(x) : no non-missing arguments to max; returning -Inf
> traceback()
4: plot.window(...)
3: localWindow(xlim, ylim, log, asp, ...)
2: plot.default(x)
1: plot(x)

With the included patch, xy.coords returns an error and plot.window is never
called:

> plot(x)
Error in xy.coords(x, y, xlabel, ylabel, log) : 
  cannot find components 'x' and 'y'

Index: xyz.coords.R
===================================================================
--- xyz.coords.R        (revision 49504)
+++ xyz.coords.R        (working copy)
@@ -62,11 +62,15 @@
            }
        }
        else if(is.list(x)) {
-           xlab <- paste(ylab, "$x", sep="")
-           ylab <- paste(ylab, "$y", sep="")
-           y <- x[["y"]]
-           x <- x[["x"]]
-       }
+        if (!is.null(x[["x"]]) && !is.null(x[["y"]])) {
+               xlab <- paste(ylab, "$x", sep="")
+               ylab <- paste(ylab, "$y", sep="")
+               y <- x[["y"]]
+               x <- x[["x"]]
+           } else {
+            stop("cannot find components 'x' and 'y'")
+        }
+    }
        else {
            if(is.factor(x)) x <- as.numeric(x)
            xlab <- "Index"
@@ -155,14 +159,18 @@
            }
        }
        else if(is.list(x)) {
-           zlab <- paste(xlab,"$z",sep="")
-           ylab <- paste(xlab,"$y",sep="")
-           xlab <- paste(xlab,"$x",sep="")
-           y <- x[["y"]]
-           z <- x[["z"]]
-           x <- x[["x"]]
-       }
+        if (!is.null(x[["x"]]) && !is.null(x[["y"]])) {
+            zlab <- paste(xlab,"$z",sep="")
+               ylab <- paste(xlab,"$y",sep="")
+               xlab <- paste(xlab,"$x",sep="")
+               y <- x[["y"]]
+               z <- x[["z"]]
+               x <- x[["x"]]
+           } else {
+            stop("cannot find components 'x' and 'y'")
+        }
     }
+    }
 
     ## Only x, y
     if(!is.null(y) && is.null(z)) {

Comment 1 Jitterbug compatibility account 2009-09-03 16:28:12 UTC
Audit (from Jitterbug):
Thu Sep  3 11:28:12 2009	ripley	moved from incoming to Graphics
Comment 2 Brian Ripley 2010-04-11 15:36:18 UTC
Changed in 2.11.0 (in a different way)