[R] Named pipe connections and stdout

Mark Myatt mark at myatt.demon.co.uk
Wed Nov 28 14:10:58 CET 2001


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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list