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

From: Greg Snow <Greg.Snow_at_imail.org>
Date: Wed, 11 Jun 2008 10:00:51 -0600

You could try passing your character string to the strwrap function first, then use cat on the result.

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow_at_imail.org
(801) 408-8111




> -----Original Message-----
> From: r-help-bounces_at_r-project.org
> [mailto:r-help-bounces_at_r-project.org] On Behalf Of Toby Marthews
> Sent: Wednesday, June 11, 2008 6:52 AM
> To: r-help_at_r-project.org
> Subject: [R] Word wrapping for character objects (WINDOWS R ONLY)

>
> Can anybody help me with this problem? ** ONLY WINDOWS R -
> PROBLEM DOESN'T OCCUR ON LINUX **
>
> 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
> ...\n")
> > 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.
>
> THANKS FOR ANY HELP!
> 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:
>
> a=c("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct

> ","Nov","Dec");menu(a)
> I guess this is a related problem?
>
______________________________________________ R-help_at_r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Received on Wed 11 Jun 2008 - 16:49:47 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 16 Jun 2008 - 10:30:44 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive