[R] Current Terminal (console) width

William Dunlap wdunlap at tibco.com
Fri Jan 20 18:04:53 CET 2017


The answer is UI-specific.

In the supplied-by-R-core Windows GUI for R, options("width") is the
current width of the command window.  If you run R in a cmd.exe window
instead of the GUI you can get the width of the cmd window by doing
some string manipulations on the output of shell("mode con",
intern=TRUE).  E.g.,
as.integer(sub("^.* ", "", grep(value=TRUE, "Columns:", shell("mode
con", intern=TRUE))))

(Setting options(width=120) when using the cmd window does not seem to
affect the input echoing - it seems to always be 80 characters.)
Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Fri, Jan 20, 2017 at 8:17 AM, Jared Studyvin <jstudyvin at west-inc.com> wrote:
> Ben,
>
> That options control is about the size of what is printed. I'm looking for
> the actual size of the window in real time.
>
> options('width') ## returns 80
> resize the terminal window
> options('width') ## returns 80
>
> Sys.getenv('COLUMNS') ## returns current window width
> resize the terminal window
> Sys.getenv('COLUMNS') ## returns a different value
>
> This however does not work on a Windows OS.
>
> Thanks,
>
>
>
>
> *Jared Studyvin, PhD *
> *Statistician*
>
>
> Environmental & Statistical Consultants
> 200 S. Second Street
> Laramie, WY 82070
> (307) 721-3179
> jstudyvin at west-inc.com
> www.west-inc.com
>
> *Follow WEST: *Facebook
> <http://www.facebook.com/pages/Western%E2%80%90EcoSystems%E2%80%90Technology%E2%80%90WESTInc/125604770807646>
> , Twitter <http://twitter.com/WestEcoSystems>, Linked In
> <http://www.linkedin.com/company/1458419>, Join our Mailing list
> <http://visitor.r20.constantcontact.com/manage/optin/ea?v=001qrD4A3S5xJ5KgMyelH9jyw%3D%3D>
>
> CONFIDENTIALITY NOTICE:  This message and any accompanying communications
> are covered by the Electronic Communications Privacy Act, 18 U.S.C. §§
> 2510-2521, and contain information that is privileged, confidential or
> otherwise protected from disclosure.  If you are not the intended recipient
> or an agent responsible for delivering the communication to the intended
> recipient, you are hereby notified that you have received this
> communication in error.  Dissemination, distribution or copying of this
> e-mail or the information herein by anyone other than the intended
> recipient, or an employee or agent responsible for delivering the message
> to the intended recipient, is prohibited.  If you have received this
> communication in error, please notify us immediately by e-mail and delete
> the original message.  Thank you.
>
> P Please consider the environment before printing.
>
>
> On Fri, Jan 20, 2017 at 8:48 AM, Ben Tupper <btupper at bigelow.org> wrote:
>
>> Hi,
>>
>> Have you looked at
>>
>> > > options("width")
>> > $width
>> > [1] 80
>>
>> and does that get at what you need?
>>
>> Ben
>>
>>
>>
>>
>> > On Jan 20, 2017, at 9:58 AM, Jared Studyvin <jstudyvin at west-inc.com>
>> wrote:
>> >
>> > Hello,
>> >
>> > On a non Windows OS the following command: Sys.getenv("COLUMNS")
>> > Will return the current width of the R terminal (console) but this does
>> not
>> > work on a Windows OS.
>> >
>> > Does anyone know equivelant R code when install on a Windows OS?
>> >
>> > I'm using WIndows 10 Pro Version: 1607; R 3.3.2
>> >
>> > Thanks,
>> >
>> > *Jared Studyvin, PhD *
>> > *Statistician*
>> >
>> >
>> > Environmental & Statistical Consultants
>> > 200 S. Second Street
>> > Laramie, WY 82070
>> > (307) 721-3179
>> > jstudyvin at west-inc.com
>> > www.west-inc.com
>> >
>> > *Follow WEST: *Facebook
>> > <http://www.facebook.com/pages/Western%E2%80%90EcoSystems%E2%80%
>> 90Technology%E2%80%90WESTInc/125604770807646>
>> > , Twitter <http://twitter.com/WestEcoSystems>, Linked In
>> > <http://www.linkedin.com/company/1458419>, Join our Mailing list
>> > <http://visitor.r20.constantcontact.com/manage/optin/ea?v=
>> 001qrD4A3S5xJ5KgMyelH9jyw%3D%3D>
>> >
>> > CONFIDENTIALITY NOTICE:  This message and any accompanyi...{{dropped:19}}
>> >
>> > ______________________________________________
>> > 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.
>>
>> Ben Tupper
>> Bigelow Laboratory for Ocean Sciences
>> 60 Bigelow Drive, P.O. Box 380
>> East Boothbay, Maine 04544
>> http://www.bigelow.org
>>
>>
>>
>>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> 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