From ripley@stats.ox.ac.uk  Tue Nov  6 19:56:54 2001
From: ripley@stats.ox.ac.uk (ripley@stats.ox.ac.uk)
Date: Tue, 6 Nov 2001 20:56:54 +0100 (MET)
Subject: [Rd] incorrect xlim error message in image() (PR#1160)
Message-ID: <200111061956.UAA18065@pubhealth.ku.dk>

1) that was not the error message, and it is not the actual error, either.
Please don't guess here: it helps immensely to have accurate subjects.

2)  I don't think this is a very good way to use image. You are
specifying the midpoints of an uneven sequence: it makes a lot more sense
to specify the break points.

3) You don't need to go to C code here: just run debug(image.default)

4) There was a bug in the algorithm to find the breakpoints from the
midpoints.   I am about to fix it.


On Tue, 6 Nov 2001 janef@stat.berkeley.edu wrote:

>
> Hi,
>
> I am having problem with R misinterpreting (x,y) values in image(). I
> downloaded the followiing binary version of R:
>
> > version
>          _
> platform i686-pc-linux-gnu
> arch     i686
> os       linux-gnu
> system   i686, linux-gnu
> status
> major    1
> minor    3.0
> year     2001
> month    06
> day      22
> language R
> > q()
> [janef@cc-jainlabx1 Poster.tahoe]$ gcc -v
> Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
> gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-81)
>
> Here is the transcript of an example:
>
>
> _______________________________________
>
> x1 <- c(6.564103,
> 13.77149,13.7715,21.66154,21.82564,26.21374,30.85128,31.0055,31.01538,32.33805,3
> 3.14872,37.42195,47.92451,54.3179,58.90297,60.55385,84.56862,100.0862,111.2681,1
> 94,194.4878,195.8302)
>
> x2 <-
> c(0,0.002242152,0.004484305,0.006726457,0.00896861,0.01121076,0.01345291,0.01569
> 507,0.01793722,0.02017937,0.02242152,0.02466368,0.02690583,0.02914798,0.03139013
> ,0.03363229,0.03587444,0.03811659,0.04035874,0.04932735,0.05156951,0.05381166)
>
> y <- 1
>
> z <-
> c(0,0.067,NA,0.167,0.083,0.05,0.067,NA,0,0.1,0,0.05,0.067,0.067,0.016,0.117,0.01
> 7,-0.017,0.2,0.35,0.134,0.15)
>
> z_matrix(z, length(z),1)
> image(x2, y, z)
> Error in image(as.double(x), as.double(y), as.integer(zi), col) :
>         invalid x / y values or limits
>
> image(x2[1:20], y, as.matrix(z[1:20,]))
>
> "OK"
>
> image(x1, y, z)
> Error in image(as.double(x), as.double(y), as.integer(zi), col) :
>         invalid x / y values or limits
>
> image(x1[1:20], y, as.matrix(z[1:20,]))
> Error in image(as.double(x), as.double(y), as.integer(zi), col) :
>         invalid x / y values or limits
>
> ________________________________________
>
> Jason Turner (jasont@indigoindustrial.co.nz) had been kindly helping me
> with figureing it out and he sugegstedd that it's a bug and sent me the
> following email:
>
> _____________________
>
>
> For giggles, I tweaked plot3d.c to track where the error occured.  The diff
> output is:
>
> !!!THIS PATCH IS A BUG TRACE, NOT A BUG FIX!!!
> --PATCH BEGINS --
> 1518a1519
> >     fprintf(stderr,"test 1\n");
> 1519a1521
> >     fprintf(stderr,"test 2\n");
> 1520a1523
> >     fprintf(stderr,"test 3\n");
> 1522,1524c1525,1542
> <     for (i = 1; i < nx; i++)
> <       if (!R_FINITE(x[i]) || x[i] <= x[i - 1]) goto badxy;
> <     for (j = 1; j < ny; j++)
> ---
> >     fprintf(stderr,"test 4\n");
> >     for (i = 1; i < nx; i++) {
> >     for (i = 1; i < nx; i++) {
> >         fprintf(stderr,"test 4 - %d\n",i);
> >       if (!R_FINITE(x[i]) || x[i] <= x[i - 1]) {
> >               if(!R_FINITE(x[i])) {
> >                       fprintf(stderr,"not a finite number\n");
> >               } else if( x[i] <= x[i-1]) {
> >                       fprintf(stderr,"x[%d] <= x[%d]\n",i,i-1);
> >                       fprintf(stderr,"%f <= %f\n",x[i],x[i-1]);
> >               } else {
> >                       fprintf(stderr,"now it looks fine\n");
> >               }
> >               goto badxy;
> >       }
> >     }
> >     fprintf(stderr,"test 5\n");
> >     for (j = 1; j < ny; j++){
> >         fprintf(stderr,"test 5 - %d\n",j);
> 1525a1544
> >     }
> --PATCH ENDS--
>
> Your transcript session with the tweaked plot3d:
>
> > x1 <- c(6.564103,
> 13.77149,13.7715,21.66154,21.82564,26.21374,30.85128,31.0055,31.01538,32.33805,3
> 3.14872,37.42195,47.92451,54.3179,58.90297,60.55385,84.56862,100.0862,111.2681,1
> 94,194.4878,195.8302)
> >
> > x2 <-
> c(0,0.002242152,0.004484305,0.006726457,0.00896861,0.01121076,0.01345291,0.01569
> 507,0.01793722,0.02017937,0.02242152,0.02466368,0.02690583,0.02914798,0.03139013
> ,0.03363229,0.03587444,0.03811659,0.04035874,0.04932735,0.05156951,0.05381166)
> >
> > y <- 1
> >
> > z <-
> c(0,0.067,NA,0.167,0.083,0.05,0.067,NA,0,0.1,0,0.05,0.067,0.067,0.016,0.117,0.01
> 7,-0.017,0.2,0.35,0.134,0.15)
> >
> > z_matrix(z, length(z),1)
> >
> > image(x2, y, z)
> test 1
> test 2
> test 3
> test 4
> test 4 - 1
> test 4 - 2
> test 4 - 3
> test 4 - 4
> test 4 - 5
> test 4 - 6
> test 4 - 7
> test 4 - 8
> test 4 - 9
> test 4 - 10
> test 4 - 11
> test 4 - 12
> test 4 - 13
> test 4 - 14
> test 4 - 15
> test 4 - 16
> test 4 - 17
> test 4 - 18
> test 4 - 19
> test 4 - 20
> test 4 - 21
> x[21] <= x[20]
> 0.052691 <= 0.053812
> Error in image(as.double(x), as.double(y), as.integer(zi), col) :
>         invalid x / y values or limits
> > ## x[20] and x[21] correspond to x2[21] and x2[22]
> > x2[21:22]
> [1] 0.05156951 0.05381166
> > ## nb - x2[22] has same value as x[20] ???
> > q()
>
> Looks like some serious confusion over the value of numbers. Or I'm
> seriously confused about they way R's main components handle arrays. Note
> that my system also passed make check (before I tweaked plot3d.c).
>
> ___________________________
>
> Thank you for all your help.
>
> Sincerily, Jane
>
>
>
> **************************************************************************************
> Jane Fridlyand, Ph.D., Bioinformatics Scientist
> UCSF Cancer Center, Box 0128 San Francisco, CA 94143-0128
> Office: Room N412 Tel: (415)514-3302 Fax: (415)502-3179
> **************************************************************************************
>
> ---------- Forwarded message ----------
> Date: Fri, 2 Nov 2001 20:32:23 +1300
> From: Jason Turner <jasont@indigoindustrial.co.nz>
> To: Jane Fridlyand <janef@stat.Berkeley.EDU>
> Subject: Re: image function
>
> Jane,
>
> When you've got the information about your system ("version" output
> and binary/source+compiler+make check info), sent that to
> r-bugs@r-project.org, along with the transcript below.  Do not copy
> r-help into that letter; those who monitor r-bugs also watch r-help,
> and they dislike duplicate messages even more than the rest of us
> (becuase they get so many).  I found this out the hard way ;-)
> Give it a nice description, such as "incorrect xlim error message
> in image()", and you'll make their job even easier.
>
> For giggles, I tweaked plot3d.c to track where the error occured (I
> can never remember how to make gdb work when I need it).  The diff
> output is:
>
>
> !!!THIS PATCH IS A BUG TRACE, NOT A BUG FIX!!!
> --PATCH BEGINS --
> 1518a1519
> >     fprintf(stderr,"test 1\n");
> 1519a1521
> >     fprintf(stderr,"test 2\n");
> 1520a1523
> >     fprintf(stderr,"test 3\n");
> 1522,1524c1525,1542
> <     for (i = 1; i < nx; i++)
> < 	if (!R_FINITE(x[i]) || x[i] <= x[i - 1]) goto badxy;
> <     for (j = 1; j < ny; j++)
> ---
> >     fprintf(stderr,"test 4\n");
> >     for (i = 1; i < nx; i++) {
> >         fprintf(stderr,"test 4 - %d\n",i);
> > 	if (!R_FINITE(x[i]) || x[i] <= x[i - 1]) {
> > 		if(!R_FINITE(x[i])) {
> > 			fprintf(stderr,"not a finite number\n");
> > 		} else if( x[i] <= x[i-1]) {
> > 			fprintf(stderr,"x[%d] <= x[%d]\n",i,i-1);
> > 			fprintf(stderr,"%f <= %f\n",x[i],x[i-1]);
> > 		} else {
> > 			fprintf(stderr,"now it looks fine\n");
> > 		}
> > 		goto badxy;
> > 	}
> >     }
> >     fprintf(stderr,"test 5\n");
> >     for (j = 1; j < ny; j++){
> >         fprintf(stderr,"test 5 - %d\n",j);
> 1525a1544
> >     }
> --PATCH ENDS--
>
> Your transcript session with the tweaked plot3d:
>
> R : Copyright 2001, The R Development Core Team
> Version 1.3.1  (2001-08-31)
>
> R is free software and comes with ABSOLUTELY NO WARRANTY.
> You are welcome to redistribute it under certain conditions.
> Type `license()' or `licence()' for distribution details.
>
> R is a collaborative project with many contributors.
> Type `contributors()' for more information.
>
> Type `demo()' for some demos, `help()' for on-line help, or
> `help.start()' for a HTML browser interface to help.
> Type `q()' to quit R.
>
> > x1 <- c(6.564103, 13.77149,13.7715,21.66154,21.82564,26.21374,30.85128,31.0055,31.01538,32.33805,33.14872,37.42195,47.92451,54.3179,58.90297,60.55385,84.56862,100.0862,111.2681,194,194.4878,195.8302)
> >
> > x2 <- c(0,0.002242152,0.004484305,0.006726457,0.00896861,0.01121076,0.01345291,0.01569507,0.01793722,0.02017937,0.02242152,0.02466368,0.02690583,0.02914798,0.03139013,0.03363229,0.03587444,0.03811659,0.04035874,0.04932735,0.05156951,0.05381166)
> >
> > y <- 1
> >
> > z <- c(0,0.067,NA,0.167,0.083,0.05,0.067,NA,0,0.1,0,0.05,0.067,0.067,0.016,0.117,0.017,-0.017,0.2,0.35,0.134,0.15)
> >
> > z_matrix(z, length(z),1)
> >
> > image(x2, y, z)
> test 1
> test 2
> test 3
> test 4
> test 4 - 1
> test 4 - 2
> test 4 - 3
> test 4 - 4
> test 4 - 5
> test 4 - 6
> test 4 - 7
> test 4 - 8
> test 4 - 9
> test 4 - 10
> test 4 - 11
> test 4 - 12
> test 4 - 13
> test 4 - 14
> test 4 - 15
> test 4 - 16
> test 4 - 17
> test 4 - 18
> test 4 - 19
> test 4 - 20
> test 4 - 21
> x[21] <= x[20]
> 0.052691 <= 0.053812
> Error in image(as.double(x), as.double(y), as.integer(zi), col) :
> 	invalid x / y values or limits
> > ## x[20] and x[21] correspond to x2[21] and x2[22]
> > x2[21:22]
> [1] 0.05156951 0.05381166
> > ## nb - x2[22] has same value as x[20] ???
> > q()
>
> Looks like some serious confusion over the value of numbers.
> Or I'm seriously confused about they way R's main components
> handle arrays (which is probably true in any case ;-).
> Note that my system also passed make check (before I tweaked
> plot3d.c).
>
> Cheers
>
> Jason
> --
> Indigo Industrial Controls Ltd.
> 64-21-343-545
> jasont@indigoindustrial.co.nz
>
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>

-- 
Brian D. Ripley,                  ripley@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 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


[Rd] incorrect xlim error message in image() (PR#1160)
ripley@stats.ox.ac.uk