[R] Smart detection of wrap width?
macqueen1 at llnl.gov
Mon Apr 20 16:59:56 CEST 2015
I'm glad it's helpful!
Defining it and then invoking it in ~/.Rprofile would work, but then you
will need to be careful about managing both ./.Rprofile and ~/.Rprofile
files. If you have one of the former, then the latter does not get sourced
at startup (see ?Startup). Of course, you can put source('~/.Rprofile') in
a local ./.Rprofile to take care of that if you want.
But in the long run, it would be a better practice to put personal helper
functions like this in a package and then load it in your .Rprofile
file(s). Most of my ./.Rprofile files have
in them (along with whatever other directory-specific startup actions I
want). The more personal helper functions you have, the more valuable it
will be to put them in a package instead of defining them in ~/.Rprofile.
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
On 4/17/15, 4:36 PM, "Paul Domaskis" <paul.domaskis at gmail.com> wrote:
>Yes, I found the width option in the help pages, but I was wondering
>if there was automatic setting of the wrapping according to the
>current window width.
>Your function works exactly as I wished. I'll probably get smarter
>with time (I hope) but would it be reasonably good practice to stick
>this into ~/.Rprofile? I don't suppose there is a way to have it
>automatically invoked when the window size/positition changes? (It's
>still priceless even without automatic triggering).
>On Fri, Apr 17, 2015 at 7:20 PM, MacQueen, Don <macqueen1 at llnl.gov>
>> A lot of this depends on what context you are running R in, e.g.,
>> Windows console, Mac console, or command line in a unix-alike. Or
>> within ESS in emacs. Those are different interfaces supported by, to
>> some extent, different people, and are based on the underlying
>> capabilities provided by the operating system.
>> Have you yet encountered
>> For example,
>> will cause wrapping at 100, at least for certain kinds of output.
>> In an xterm shell running in an X windows context, I frequently use
>> setwid <- function ()
>> if (!interactive())
>> scon <- pipe("stty -a")
>> stty <- scan(scon, what = "", sep = ";", quiet = T)
>> cstr <- stty[grep("columns", stty)]
>> options(width = as.numeric(gsub("[^0-9]", "", cstr, ignore.case =
>> paste("width =", options()$width, "\n")
>> A function I wrote that resets the width option to match the window
>> widths, and therefore adjusts the wrapping after I resize a windwo.
More information about the R-help