[Rd] pdf() behavior (PR#1174)

ripley@stats.ox.ac.uk ripley@stats.ox.ac.uk
Sat, 17 Nov 2001 11:56:58 +0100 (MET)


Once again, this has nothing to do with pdf()!

The bug is in the internal clipping code in graphics.c, which read

    default: /* Partial clipping; draw poly[line|gon] */
        dd->gp.xpd = 2;
        result2 = clipCircleCode(x, y, coords, ir, dd);
        dd->gp.xpd = xpdsaved;
        if (dd->dp.canClip && result2 == -2) {
            GClip(dd);
            dd->dp.circle(x, y, coords, ir, bg, fg, dd);
        }
        else {
            vmax = vmaxget();
            xc = (double*)R_alloc(result+1, sizeof(double));
            yc = (double*)R_alloc(result+1, sizeof(double));

with result, not result2.  This meant that if a circle was clipped by the
plot region but not by the device region, result got set to -2, and the
final lines tried to allocate a vector of size -1.  As the postscript
device has dd->dp.canClip true, the bug was avoided on that device.

I don't fully understand the intended logic: is this fix the correct one,
Paul or Ross?  And can we have some comments in the code, please?


On Thu, 15 Nov 2001 White.Denis@epamail.epa.gov wrote:

> The attached script produces "Error in plot.xy ... negative length
> vectors are not allowed" when using pdf() but not when using postscript
> ().
>
> platform sparc-sun-solaris2.8
> arch     sparc
> os       solaris2.8
> system   sparc, solaris2.8
> status
> major    1
> minor    3.1
> year     2001
> month    08
> day      31
> language R
>
> ------------------------------------
> # script
> PDF <- TRUE
>
> f.v1 <- function (x, a, b) b * (x^a)
> f.v2 <- function (x, a, b, d) b * (x^a) * exp(d*x)
>
> dat <- scan ("test.dat")
>
> if (PDF) pdf ("test.pdf", width=8.5, height=11) else
>   postscript ("test.eps", horizontal=FALSE, onefile=FALSE)
>
> par (mfrow=c(2,1), mar=rep(6,4))
>
> n <- length(dat)
> nseq <- seq (n)
>
> fit <- lm (log (dat[nseq]) ~ log (nseq))
> b <- exp (fit$coefficients[1])
> a <- fit$coefficients[2]
> plot (dat[nseq], pch=20)
> points (sapply (nseq, f.v1, a, b), col="red", pch=20)
>
> fit <- lm (log (dat[nseq]) ~ log (nseq) + nseq)
> b <- exp (fit$coefficients[1])
> a <- fit$coefficients[2]
> d <- fit$coefficients[3]
> plot (dat[nseq], pch=20)
> points (sapply (nseq, f.v2, a, b, d), col="red", pch=20)
>
> graphics.off ()
>
> -----------------------------------
> # data set
> 9.585
> 12.935
> 14.775
> 15.625
> 16.56
> 17.44
> 18.165
> 18.655
> 19.04
> 19.49
> 19.9
> 20.285
> 20.61
> 20.815
> 21.065
> 21.3
> 21.46
> 21.645
> 21.82
> 22.085
> 22.315
> 22.45
> 22.61
> 22.67
> 22.79
> 22.9
> 23.01
> 23.1
> 23.165
> 23.295
> 23.4
> 23.51
> 23.585
> 23.64
> 23.685
> 23.75
> 23.805
> 23.84
> 23.9
> 23.955
> 24.025
> 24.09
> 24.14
> 24.18
> 24.23
> 24.275
> 24.31
> 24.33
> 24.345
> 24.37
>
>
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> 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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._