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.
Or you could call those other programs from within R. See ?system 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 >
On Mon, 7 Nov 2005, Stuart Macgregor 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.[I don't think your machine _is_ 'fast'! I am seeing 0.3s for a complete R session on an Opteron 250. We have worked hard to reduce the start-up time to those levels over the period you quote: please do not belittle those efforts. R is fast (several times at least) compared to all other software I use of similar complexity.] On my 2-year-old i386 box a complete empty session takes 0.5s. You can reduce that a lot by using fewer default packages. For example, if you don't need methods or graphics or datasets, R_DEFAULT_PACKAGES="utils,stats" reduces that to 0.3s, and R_DEFAULT_PACKAGES=NULL reduces it to 0.05s. We use the latter when using R for scripting (e.g. in R CMD INSTALL). -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595