[Rd] documentation error par("cin") and par("cra") (PR#7227)

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Sep 14 17:06:50 CEST 2004


On Tue, 14 Sep 2004 joehl at gmx.de wrote:

> the help of par() claims that 
> cin and cra are 
> c(width, height)

That is the design intention.

> but it appears to be rather 
> c(height, width)

On what evidence?  W has no descenders, so its height is less than the
typical box.  It's coincidence, BTW, that the numbers are the same: I get

> par("cin")
[1] 0.15 0.20
> strheight("W", unit="inches")
[1] 0.1196667

and characters are on average taller than they are wide.  strheight
reports the same for all characters, but strwidth does not.

Here is the code (in par.c)

    else if (streql(what, "cin")) {
	value = allocVector(REALSXP, 2);
	REAL(value)[0] = Rf_dpptr(dd)->cra[0]*Rf_dpptr(dd)->ipr[0];
	REAL(value)[1] = Rf_dpptr(dd)->cra[1]*Rf_dpptr(dd)->ipr[1];
    }

cra is set in the driver, and postscript has

    dd->cra[0] = 0.9 * pointsize;
    dd->cra[1] = 1.2 * pointsize;

whereas windows() has

    gcharmetric(xd->gawin, xd->font, -1, &a, &d, &w);
    dd->cra[0] = w * xd->rescale_factor;
    dd->cra[1] = (a + d) * xd->rescale_factor;

so it really is (width, height).  OTOH, strheight doesn't look at the 
character, just the height of "M" (no descenders).  See the comment

        /* cra is based on the font pointsize at the
         * time the device was created.
         * Adjust for potentially different current pointsize
         * This is a crude calculation that might be better
         * performed using a device call that responds with
         * the current font pointsize in device coordinates.
         */
         /* Add in the ascent of the font, if available */

-- 
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



More information about the R-devel mailing list