[R] slow R start up
(Ted Harding)
Ted.Harding at nessie.mcc.ac.uk
Mon Nov 7 09:57:21 CET 2005
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).
This would be the converse of running systen commands from within
R using 'system()'.
However, there can be issues with this approach since, in my
experience, you have to ensure that the program reading the
FIFO knows when there is more to come on the FIFO, and also
when to stop reading. In principle it's straightforward,
though, and rather like reading the commamnds simply from
a file.
Or you might emulate the whole thing using regular files:
Put R into a loop which reads commands from a file (testing
whether it has changed) which the shell script updates as
needed. But you'd need to be careful that R does not read
a partially updated file.
Best wishes,
Ted.
> On 11/7/05, Stuart Macgregor <stuart.macgregor at qimr.edu.au> wrote:
>> Hi,
>> I want to use R within a unix shell script where I repeatedly open
>> and close R (doing some computation within R whilst it is open). i.e.
>> something like
>>
>> #!/bin/sh
>> R --vanilla << EOF
>> # some R commands
>> EOF
>> # some unix commands
>> R --vanilla << EOF
>> # some R commands
>> EOF
>> # some unix commands
>> ...etc
>>
>> the problem is that since I open and close R many times, the shell
>> script takes a long time to run (R takes ~1 second to start up, even
>> on
>> a fast machine; I've tried various linux installations and versions of
>> R
>> from 1.7 to 2.2). Is there some way of making R start up faster? I've
>> tried altering the memory start options but this makes little
>> difference.
>> Note I have various other programs called from the shell script and
>> don't want to do everything from "within" R.
>> One possible solution may be to send the relevant commands to an
>> already
>> running copy of R but I've yet to figure out how to achieve this.
>>
>> Any suggestions gratefully received.
>>
>> Stuart.
>>
>> ______________________________________________
>> R-help at stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide!
>> http://www.R-project.org/posting-guide.html
>>
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 07-Nov-05 Time: 08:57:16
------------------------------ XFMail ------------------------------
More information about the R-help
mailing list