[R] text on some lines

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Jul 26 16:24:18 CEST 2005


On Tue, 26 Jul 2005, Uwe Ligges wrote:

> Navarre Sabine wrote:

>> I would like to write text on 2 lines for example.
>> For example, if you have a long sentence and you want to cut it
> at the 45 caracter and put the continuation underneath!
>> Is it possible?
>
> Do you mean for output to console / in plots?
> Simply insert a "\n" (newline), for example.

And strwrap() will help you insert it in the right place, e.g.

> x <- "For example, if you have a long sentence and you want to cut it at the 45 caracter and put the continuation underneath!"
> strwrap(x, 45)
[1] "For example, if you have a long sentence"
[2] "and you want to cut it at the 45 caracter"
[3] "and put the continuation underneath!"
> paste(strwrap(x, 45), collapse="\n")
[1] "For example, if you have a long sentence\nand you want to cut it at the 45 caracter\nand put the continuation underneath!"

the latter for use when plotting.


-- 
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-help mailing list