Skip to content

how to run R as a daemon

5 messages · Marsland, John, Laurent Faisnel, Brian Ripley

#
Why not run R as a separate process using the RSOAP package.
You can then converse with R as a web service using the NuSOAP PHP class as
described in the case of the Amazon example below:
http://www.devshed.com/Server_Side/PHP/AmazonAPI/AmazonAPI1/page3.html

John Marsland
********************************************************************** 
This is a commercial communication from Commerzbank AG.\ \ This ... {{dropped}}
#
I  just visited the link you gave me. One of the problems that could 
occur using NuSOAP is that I do not intend using Python. Thanks anyway. 
I would also like to ask more precise questions :
- is it possible to run R as a standalone service, which runs in 
background indefinitely, waiting for instructions ? This would be a 
great improvement for me, since each time it is launched R has to 
re-load a (constant) matrix generated thanks to a database connection 
(takes a very long while)
- my R script is object-oriented; I define classes and methods, but I'm 
not so sure about how methods should be declared; I usually write 
something like :

mymethod <- function(.Object) UseMethod("mymethod",.Object);

setMethod("mymethod","myclass",
        function(.Object)
        {
            # instructions
            return(.Object);
        }
        );

Perhaps is this not the best way to write methods ? Could this explain 
the following fact : when I run the script, R spends about 1/3 of its 
thinking time creating the generic functions linked with my methods. 
Isn't this wasted time ? The same script may be executed many times 
consecutively by different users, and each time R has to re-define the 
generic functions ! (are always the same)

I use R 1.6.2 on a Linux server (Red Hat - soon Debian)
Marsland, John wrote:

            
#
On Mon, 19 May 2003, Laurent Faisnel wrote:

            
`more precise'?  At least some of the inefficiencies are emerging, but I
still have little picture of what you are actually trying to do.  It ought
to be possible to run a new R session in a well under a second (on a 1+GHz
machine):

gannet% time env R_DEFAULT_PACKAGES=NULL R --vanilla --slave < /dev/null
0.203u 0.039s 0:00.27 85.1%     0+0k 0+0io 1220pf+0w

for example (on a dual Athlon 2600, R 1.7.0).
It is, but waiting for instructions from one place (stdin or on a socket).
There is some danger of different jobs sent leaving things behind that 
will cause interactions.
You could just save and then load that matrix in your .RData
Yes, but it is your usage that is the problem.  You are mixing S3 and S4
methods (where did you copy an example like that from?).  You should
dump your scripts if you use S4 methods (which I don't think you should be
doing in such simple examples, nor if you care about speed):  see the
examples of S4-using packages on CRAN (e.g. DBI, SparseM).

Also consider upgrading to R 1.7.0 and setting R_DEFAULT_PACKAGES to what 
you actually need (and omit methods if you don't need it)
#
Prof Brian Ripley wrote:

            
I don't understand how you made this test. What does "gannet%" mean? 
Anyway, when I launch R with these options (--vanilla and --slave), it 
is fast enough.
This is a good piece of news. But how ?
I 'll make some tests about possible interactions if I successfully 
launch R in such a mode.
Seems to be a good idea. I'm not used to edit my .RData but sure it 
would be an improvement. I had not even thought about it.
I clearly prefer using S3 classes & methods. I knew S4 classes would 
cause slowness problems. But I did not find a clear documentation about 
differences between S3 and S4. Neither did I find detailed tutorials 
about R programming. Which part of my code structure is S3-like and 
which one is S4-like ? Is the above-mentionned problem S4 classes' fault 
? You mean with clean S3 scripts I would have none of these drawbacks ?
I won't use R 1.7.0 for the time. First everything has to work fine with 
R 1.6.2. I think I have few things in R_DEFAULT_PACKAGES, and I cannot 
omit methods because I use them all !

Thank you for your answer.
Laurent
#
On Mon, 19 May 2003, Laurent Faisnel wrote:

            
A totally standard Unix prompt: machine_name% is the default prompt in 
csh.
There's a book called `S Programming' that has all this crystal clear, and 
it is in the FAQ!
That's the `methods' package, only needed for S4 methods.