A tty Connection for R

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(-)