I'd like to put the following in my .Rprofile:
# auto width adjustment
.adjustWidth <- function(...){
options(width=Sys.getenv("COLUMNS"))
TRUE
}
.adjustWidthCallBack <- addTaskCallback(.adjustWidth)
This will dynamically resize the max columns in my R session to be the width of the window. This works in an interactive session, but when doing something like R CMD INSTALL or a batch session I always get:
Error in options(width = Sys.getenv("COLUMNS")) :
invalid 'width' parameter, allowed 10...10000
Execution halted
How can I fix this? I assume the issue is that Sys.getenv("COLUMNS") is failing somehow? Is there some if() statement I could do that lets me detect if I run in batch or not? The original auto width adjustment code isn't mine, I found it somewhere else online.
Maybe wrapping the option in a try
function helps:
try( options(width=Sys.getenv("COLUMNS")), silent = TRUE)
For me COLUMNS
doesn't get updated when my X terminal window (vte based, on linux) gets resized while R is running, since it gets updated by bash after each command. (according to the accepted answer for this question)
I found a hint towards a better solution on this page. It talks about a resize
command for solaris, but also mentions stty
, which linux does have.
So after reading the man-page (and some basic R questions), I came up with this:
# auto width adjustment
if(interactive()) {
.adjustWidth <- function(...){
options('width' = sapply(strsplit(system("stty size", intern = T), " "), "[[", 2))
TRUE
}
.adjustWidthCallBack <- addTaskCallback(.adjustWidth)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With