views:

101

answers:

3

(Asking this on behalf of a member of our Bay Area R Group. I did not have a ready answer as I run ESS within Emacs. I assume this question refers to running R within the command-line environment that ships in the standard Windows distribution).

I'm new to R, but what I've found in searching for my answer is that there isn't anything about customizing R so that I can work faster.

One of my main problems is the lack of word wrapping in my version running on Windows XP. I noticed that my friends with the Mac OS have word wrapping.

Is there a way to enable word wrapping in R running on a Windows machine?

A: 

Well I tried the same, but the component they use in Windows GUI obviously does not have that feature. Where was the word wrapping option in the Mac menu ?

whatnick
+1  A: 

Shane points out that this does not work on the Windows R application, so I'm marking this as CW in case someone on another platform stumbles across this question.


I don't have Windows handy to try it on, but you might be able to use options(width=XXX) to accomplish word-wrap.

> rnorm(20)
 [1]  1.5096142  2.5213651  1.6129801  1.2328282  0.1099109  0.7681205
 [7]  0.7408279  0.1853688  0.2679453 -1.4006292  0.5178583 -0.8838526
[13] -1.5162541 -1.5603825 -0.7217159  2.3466593  0.7382550  1.6618710
[19]  1.3201585  0.2872295
> options(width=50)
> rnorm(20)
 [1] -0.990605829 -1.479986280 -0.670011156
 [4]  1.545288381  1.749429922 -0.386976121
 [7]  0.152663018  0.537898605  0.307018436
[10] -1.214402678 -0.066987719 -0.003181806
[13]  0.775656734 -1.084597991  1.419298825
[16]  1.634812239 -0.234720361 -1.232159240
[19] -0.560096460  0.167267767

And here's the R help for options, for reference:

'width': controls the maximum number of columns on a line used in printing vectors, matrices and arrays, and when filling by 'cat'.

Columns are normally the same as characters except in CJK languages.

You may want to change this if you re-size the window that R is running in. Valid values are 10...10000 with default normally 80. (The limits on valid values are in file 'Print.h' and can be changed by re-compiling R.) Some R consoles automatically change the value when they are resized.

Mark Rushakoff
The windows console automatically changes this when it's resized.
Shane
+3  A: 

I think that the issue happens with long strings. Here I create a character vector:

> z <- "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"

Then, on Windows, depending on the display size, it will look like this:

> z
[1] "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz zzzzzzzzzzzzzzzzzzzzzzz$

With a $ sign at the end. Setting the width option has no effect for a long character vector. In fact, in the Windows GUI, by default it sets the option(width) automatically on resize.

I don't believe that there are any global options to address this. You might try using the strwrap() function.

> strwrap(z, width=60)
[1] "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"   "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"   
[3] "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"   "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
Shane