[R] Named pipe connections and stdout

Duncan Temple Lang duncan at research.bell-labs.com
Wed Nov 28 14:50:58 CET 2001


Hi Mark,
 Just some remarks on what may be available on this front in the near future.

Many months ago, I did extend the "event loop" in R to handle events
on connections (i.e. setReader()) and allow timers. Unfortunately, I
did not get to commit it the public R code. However, I do plan on
doing so quite soon and making the event loop more friendly to Tcl/Tk,
Gtk, etc.  when they run in R and when R runs within those
applications.  Given the imminent release of R-1.4.0, the changes will
not be in that version, but will be in soon after.

Also, I am just about to complete the RGtk package which provides R
bindings to the Gdk and Gtk libraries. This is a possible alternative
to Tcl/Tk and it appears to have more widgets. Of course, Tcl/Tk is on
many machines and is known to work on Unix, Windows and Mac.  Gtk
should work on Unix and Windows without much difficulty, and is being
ported to the Mac.  Most of the code is automatically generated from
what are termed .defs files describing the libraries and so it is a)
less buggy than manually generated code, b) easy to add new libraries
(e.g. the Gnome application library).


 D.


Mark Myatt wrote:
> Jim,
> 
> >I've been trying to find out about how to connect NEdit to R using
> >something like the system() command, but reading the input line by line.
> >NEdit sends its stdout connection back to the program that invoked it,
> >and it is quite easy to get blocks of text piped back from NEdit.
> >However, I have not succeeded in working out how to get R to process the
> >input, except in the rather trivial way of processing it all at once
> >when NEdit exits.
> 
> I have not used NEdit and so will be of little help on that. Does NEdit
> use something like Perl, Python or Tcl as its macro language? If so,
> then you should be able to get something up and running by sending R a
> line at a time through a pipe. I think the important thing would be to
> set the FIFO connect in R to blocking and ensure that each line sent to
> R is terminated with an EOL.
> 
> Perhaps I can tell you what / where I am up to? For all the usual
> reasons, I have made a decision to move all my work to Linux. I find the
> terminal based interface to R works but is a bit lacking. I know about
> ESS but groan at the sound and look of the word 'emacs'. Inspecting ESS
> code might provide some insight.
> 
> I felt that, In getting to know Linux, it would be a good idea to hack a
> GUI shell that would make using R a bit more pleasurable. This lead to
> my query to the list.
> 
> My thinking on this is to:
> 
>         1. Develop a shell with an editor window (that accepts R code
>         that can be submitted in blocks to R), and an output window that
>         displays the R output. This would be extensible so that (e.g.)
>         menus that call functions could be easily added by simply
>         editing an external text file and have syntax highlighting in
>         the editor. I have, more or less, decided on using Tcl/TK for
>         this.
> 
>         2. Connections between R and the shell will be handled using
>         named pipes. I might need to hack a simple communications
>         protocol so that the shell can tell when R is ready to accept
>         input, pass input to R on a line by line basis, tell when R has
>         some output, tell R that output can be received, &c. although
>         most of this might be able to be done automatically using the
>         options available to configure FIFOs in R. Simple experiments
>         show that this should be relatively easy to code in both R and
>         Tcl. One problem that I have is the loss of stdout without
>         explicit calls to print() which provides different output from
>         the standard terminal output and is particularly annoying as <-
>         assignments print out the contents of the assignment.
> 
> >Could you point me to some documentation about this? I got a deathly
> >silence last time I asked on the list...
> 
> There is little documentation on this. Brian Ripley has a brief piece on
> connections in RNEWS 1:1, Peter Dalgaard presents a similar listener /
> evaluator function in the context of writing a simple shell in Tcl/TK
> from within R in RNEWS1:3. John Chambers discusses this in:
> 
>         Chambers, J. M. (1998) Programming with Data. A Guide to the S
>         Language. Springer
> 
> But a lot of that applies to S not R (e.g. setReader() is not available
> in R). Trying help(fifo), help(readLines) provides some info and useful
> links around the help system.
> 
> It is a bit like the blind leading the blind. Sorry. Perhaps we can
> share experiences.
> 
> I have posted this to R-Help in the hope that someone might pick it up.
> 
> Mark
> 
> --
> Mark Myatt
> 
> 
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

-- 
_______________________________________________________________

Duncan Temple Lang                duncan at research.bell-labs.com
Bell Labs, Lucent Technologies    office: (908)582-3217
700 Mountain Avenue, Room 2C-259  fax:    (908)582-3340
Murray Hill, NJ  07974-2070       
         http://cm.bell-labs.com/stat/duncan
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list