[R] Smart detection of wrap width?

MacQueen, Don macqueen1 at llnl.gov
Sat Apr 18 01:20:55 CEST 2015


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
  options()$width
?
For example,
  options(width=100)
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())
        return(invisible(NULL))
    scon <- pipe("stty -a")
    stty <- scan(scon, what = "", sep = ";", quiet = T)
    close(scon)
    cstr <- stty[grep("columns", stty)]
    options(width = as.numeric(gsub("[^0-9]", "", cstr, ignore.case = T)))
    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.

-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 4/17/15, 3:52 PM, "paul" <paul.domaskis at gmail.com> wrote:

>I suspect that the answer is "no", but just in case, is there a way to
>have R detect the window width and wrap accordingly?  I don't want to
>set an option every time I dock a window or shrink it.
>
>In my ideal paradise, R would not only format output according to
>window width, but it would also me to specify a virtual window width.
>So if I specify a virtual window width of 200 characters, and the
>actual window width is 100, then the output has a carriage return at
>the 200 character mark but I only see the 1st 100 characters of each
>line of text (the rest being truncated from view).  And of course, the
>user would be able to specify when the virtual width mirrors the
>actual window width.
>
>I know that this is dreaming in technicolour (which is not that
>fantastical these days), but I would be pleasantly surprised if there
>was a way to simply have the output wrap according to the actual
>window width.
>
>______________________________________________
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>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.



More information about the R-help mailing list