A tty Connection for R

July 26, 2010

(This article was first published on BioStatMatt » R, and kindly contributed to R-bloggers)

I completed (some time ago) an initial version of a patch for R, version 2.11.1, that adds a POSIX tty connection. The patch is confirmed to compile and works on Mac OS X (thanks to Ashwin Bhat of Georgia Tech) and Debian GNU Linux. However, it should be portable to other POSIX compliant operating systems.

The tty patch allows for a variety of interesting operations in R, including “Press any key to continue” type functionality, reading passwords from the terminal without echoing the characters, and communications with any device that emulates a tty (i.e. /dev/tty*). I had originally developed the patch in order to collect data from a microcontroller via a virtual (USB) serial port.

I plan to write more about the patch with examples in the future. However, for now, I will just post the code, which is licensed according to the GPL version 2. Users familiar with the POSIX tty interface should be able to use the function (tty) easily. Instructions to compile the patch are essentially identical to those that I wrote for the earlier serial connection patch, replacing serial with tty in the appropriate places. The patch code is here R-2.11.1-tty.patch.

The patch is relatively small. Most of the code relates to parsing arguments to the tty function, as the POSIX tty interface has may options. Below are the results of diffstat

$ diffstat R-2.11.1-tty.patch
 configure.ac                        |    2
 src/include/Internal.h              |    2
 src/library/base/R/connections.R    |    6
 src/library/base/man/connections.Rd |   71 ++-
 src/main/connections.c              |  835 ++++++++++++++++++++++++++++++++++++
 src/main/names.c                    |    1
 6 files changed, 903 insertions(+), 14 deletions(-)

To leave a comment for the author, please follow the link and comment on their blog: BioStatMatt » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags: , , , ,

Comments are closed.


Mango solutions

RStudio homepage

Zero Inflated Models and Generalized Linear Mixed Models with R

Quantide: statistical consulting and training



CRC R books series

Contact us if you wish to help support R-bloggers, and place your banner here.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)