[R] slow R start up

(Ted Harding) Ted.Harding at nessie.mcc.ac.uk
Mon Nov 7 22:03:35 CET 2005


On 07-Nov-05 Ted Harding wrote:
> 
> On 07-Nov-05 Gabor Grothendieck wrote:
>> Or you could call those other programs from within R.  See
>> ?system
> 
> A possibility which might work, and if so would work as you intend,
> is to use a FIFO ("named pipe") or two to communicate with R.
> 
> In R, see "?connections"; in Linux, see "man mkfifo".
> 
> Then you should be able to start R up so that it reads commands
> from the FIFO, (and optionally writes output to a FIFO which can
> be read by the shell script; though it might be simpler to write
> the output to a regular file).

Here is a bare and thin skeleton, which you may be able to develop.
You'll need two windows for this demo, one for R and one for the
Linux shell, both operating in the same directory.


In the R window, start up R


In the Linux window, execute

mkfifo -m 666 Rin


In R:

Rin<-fifo("Rin",open="T")
online<-TRUE
while(online){source(Rin)}


In Linux:

cat > Rin  << EOF
x<-0.1*(0:10)
plot(x,cos(2*pi*x))
EOF
sleep 10
cat > Rin  << EOF
x<-0.1*(0:20)
plot(x,sin(2*pi*x))
online<-FALSE
EOF

You can then "rm Rin" in Linux.


That is a little script which sends commends to R via the FIFO
to do two (slightly) different things, with a pause between them.

R reads the FIFO so long as "online" is TRUE, and then stops
reading when told that "online" is FALSE. Whenever it has emptied
the FIFO for the moment (as happens at the "sleep 10" in Linux)
it simply waits in the loop for more to come through.

You could add a line in R following the "while" to

close(Rin)

or to quit() so that R closes down at that point.

>From that beginning you should be able to develop scripts which
send arbitrary commands to R from Linux.

PS: This is my first venture into the FIFO world where using R
is concerned, so I may have under-exploited the possibilities
of R in this respect. It is simply based on how I've done it
with other software, and this is a very generic way to do it.

Hoping this helps,
Ted.


--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 07-Nov-05                                       Time: 21:03:32
------------------------------ XFMail ------------------------------




More information about the R-help mailing list