From ripley@stats.ox.ac.uk  Wed Apr 17 08:03:36 2002
From: ripley@stats.ox.ac.uk (Prof Brian D Ripley)
Date: Wed, 17 Apr 2002 08:03:36 +0100 (BST)
Subject: [Rd] Using strwidth before plotting
In-Reply-To: <Pine.GSO.4.44.0204170731210.28088-100000@auk.stats>
Message-ID: <Pine.GSO.4.44.0204170750360.28140-100000@auk.stats>

On Wed, 17 Apr 2002, Prof Brian D Ripley wrote:

> On Tue, 16 Apr 2002, Duncan Murdoch wrote:
>
> > In the plotcorr() function in the ellipse package, I want to position
> > things differently depending on the size of the labels.  I can use
> > strwidth to find out the length of the labels, but only when there's a
> > plot window open:  it won't open one.
> >
> > Question:  What function call says:  make sure there's a window open
> > (i.e. do what plot() does before it starts plotting)?
>
> Call par(), e.g. par("font")
>
> > I don't think I can use plot.new() or frame(), because I don' t want
> > to leave a blank page in the plot history if there was already a
> > window open.
>
> (That is indeed what happens.)

However, you could use plot.new(); par(new=TRUE)

> You can find if there is a device open by looking at length(.Devices) > 1
> or dev.cur() > 1.

What the internal code does can be reproduced in R by

if(length(.Devices) == 1 || dev.cur() == 1) {
    dev <- getOption("device")
    if(is.character(dev) && length(dev) > 0) get(dev)()
}

dev.cur includes a check that .Devices exists, but it is created in
InitGraphics before interactive R code is accepted, so the check must
always succeed and the above code is safe.

-- 
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] Using strwidth before plotting
Prof Brian D Ripley