Skip to content
Prev 350099 / 398506 Next

Smart detection of wrap width?

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.