From ripley@stats.ox.ac.uk  Wed Aug 14 17:59:03 2002
From: ripley@stats.ox.ac.uk (ripley@stats.ox.ac.uk)
Date: Wed, 14 Aug 2002 17:59:03 +0100 (BST)
Subject: strwidth
In-Reply-To: <Pine.LNX.4.21.0208141845490.9596-100000@artemis>
Message-ID: <Pine.LNX.4.31.0208141756030.18789-100000@gannet.stats>

On Wed, 14 Aug 2002, Torsten Hothorn wrote:

> I need to determine the width of a string before plotting it to the
> current device because I want to adjust `mai' to have
> the necessary space available. It seems to me that this is an "hen and
> egg" problem:

`chicken and egg' is idiomatic.

> R> a <- "test"
> R> strwidth(a)
> Error in strwidth(a) : plot.new has not been called yet
>
> # ok, I need an open device
>
> R> plot(1:2, type="n")
> R> strwidth(a)
> [1] 0.04760034
>
> fine. But I can't continue to plot to the current device because I need to
> reset `mai', so I need a second one ...

Ah, but you don't need a coordinate system:

> a <- "test"
> plot.new()
> par(mai=rep(30*strwidth(a), 4))
> plot(1:2)

works.

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


strwidth
ripley@stats.ox.ac.uk