strwidth

ripley@stats.ox.ac.uk ripley@stats.ox.ac.uk
Wed, 14 Aug 2002 17:59:03 +0100 (BST)


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