image() with all NAs fails (PR#8228)
On Thu, 20 Oct 2005 murdoch at stats.uwo.ca wrote:
On 10/20/2005 12:41 PM, barry.rowlingson at gmail.com wrote:
Full_Name: Barry Rowlingson Version: 2.2.0 OS: Linux Submission from: (NULL) (194.80.32.8) The image function with a matrix of all NA values fails with:
xyz=list(x=1:3,y=1:4,z=matrix(NA,3,4)) image(xyz)
Error in image.default(xyz) : invalid z limits In addition: Warning messages: 1: no finite arguments to min; returning Inf 2: no finite arguments to max; returning -Inf Image can handle any number of NAs as long as there is at least one data value:
xyz=list(x=1:3,y=1:4,z=matrix(c(1,rep(NA,11)),3,4)) image(xyz)
and shows NAs as transparent. However if it is all NAs then the z-limit calculation breaks down as above. It seems reasonable to me that image() with all NAs should produce a completely transparent/empty image (after displaying the axes if add!=TRUE) and not fail with an error.
I agree, though I think the warnings are reasonable and a fix shouldn't
remove them. However, I'm not sure what the fix should be. There's a
test in image.default
if (any(!is.finite(zlim)) || diff(zlim) < 0)
stop("invalid z limits")
that is throwing the error. We want the error if a user specifies
diff(zlim) < 0 or non-finite z limits, we just don't want it if all the
z's are NA. But a test all(is.na(z)) looks a bit expensive for such a
rare case.
It is not actually documented that zlim can be omitted (something we need to fix too). Why not just add a check for zlim not being missing to that test?
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