[R] Word wrapping for character objects (WINDOWS R ONLY)

Toby Marthews Toby.Marthews at lsce.ipsl.fr
Wed Jun 11 14:52:01 CEST 2008

Can anybody help me with this problem? ** ONLY WINDOWS R - PROBLEM DOESN'T

I want to print a long character to screen:

> getOption("width")
[1] 60
> z=(1:20)/10    #z is a vector of length between 20 and 30 (depending on
user options) containing lengths in mm (i.e. each element is 1-5
characters long)
> str1=paste("The depths chosen are (",toString(z),") mm, and more text
> cat(str1)
The depths chosen are ( 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1,
1.1, 1.2, 1.3, 1.$

The problem is that on R for Windows the string is cropped by the window
size (hence the "$"). On R for Linux, this doesn't happen and the text is
"word wrapped" (the default for the shell, I guess):

> cat(str1)
The depths chosen are ( 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1,
1.1, 1.2, 1.3,
1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2 ) mm, and more text ...

I can't find any option for "word wrapping" in the cat command (fill=TRUE
has no effect). I also checked the menu Edit -> GUI preferences..., but
there doesn't seem to be a "Word Wrap" option there either.

How do I get word wrapping like this in Windows? Perhaps the attached
screenshots clarify this question.

Toby Marthews

Previous relevant posts:

- The post from 2006 about Screen Wrapping
(http://tolstoy.newcastle.edu.au/R/help/06/05/26673.html) which Brian
Ripley answered was about controlling how long vectors are cropped to the
screen. Unfortunately, the width option in options() does not affect
character objects, so I can't use that control here.

- I sent the same question to r-sig-gui at stat.math.ethz.ch in Oct 2007, but
noone there could help me with it.

- Try the following command on Windows R with a small window
(getOption("width")<117) and a large window (getOption("width")>117) and
you'll see you get extra nonexistent options in the menu:
I guess this is a related problem?

More information about the R-help mailing list