Sourcing r-files only once on Rserve
Asked Answered
P

2

5

I have written a small Java client which does some calculations on an Rserver. For this purpose, there are functions.r- and libraries.r files on the server side, which have to be sourced, before the actual calculation can be done.

Currently I load the files on every new connection:

import org.rosuda.REngine.Rserve.RConnection;

public class RserveTester {

  public void doOnRserve() {
    RConnection c = new RConnection( "rserve.domain.local" );
    c.login( "foo", "user" );
    c.eval("source(\"/home/rserve/lib/libraries.r\")");
    c.eval("source(\"/home/rserve/lib/functions.r\")");
    c.eval( "someCalculation()" )
    c.close();
  }  
}

where doOnRserve() is called due to some events on the client side couple of times in a minute.

My Question is: Is it possibility to source the libraries only once, such that they are available during all new RSessions without individual sourcing?

I tried on the client side something like:

c.serverSource("/home/rserve/lib/libraries.r" )
c.serverSource("/home/rserve/lib/functions.r" )

Which gives me te following exception (no idea why this does not work wile eval does):

 org.rosuda.REngine.Rserve.RserveException: serverSource failed, request status: access denied (local to the server)

Can I start the Rserve with a specific .Rprofile?

EDIT:

Basically, there seam to be three possible methods:

  1. Let the /home/rserve/.Rprofile source the .r files. But this seams to source them each time I call new RConnection()
  2. Passing the source commands directly to R when starting Rserve (no idea how to do this).
  3. My preferred method: doing it from the client side using serverSource(), which throws these "access denied" exceptions.

EDIT2:

Rserve version v0.6-8 (338)

R version 2.15.2 for x86_64-pc-linux-gnu.

Padgett answered 25/11, 2012 at 17:17 Comment(0)
F
7

This is trivially done by adding source lines to your configuration file, i.e., putting

source "/foo/bar.R"

in /etc/Rserv.conf will source /foo/bar.R on startup. If you want to use another config file, use --RS-conf command line argument to specify it. Finally, Rserve 1.x supports --RS-source option on the command line as well.

Without the quotations in the filepath, it may give File Not Found Error.

BTW: you mentioned serverSource() access denied - that means you did not enable control commands in Rserve (control enable in the configuration or --RS-enable-control on the command line).

PS: Please use stats-rosuda-devel mailing list for Rserve questions.

Fawn answered 29/11, 2012 at 21:22 Comment(3)
Thanks, but concerning the serverSource both methods you mentioned don't work: Starting the daemon with R CMD Rserve --RS-enable-control --RS-conf ~/control/Rserve.conf gives a warning on startup: "Warning: unkown Option '--RS-enable-control'". Adding control enable to (my local) Rserve.conf gives no warning but then I still get the Java exception: "serverSource failed, request status: access denied (local to the server)"Padgett
If --RS-enable-control is not recognized then you're using older Rserve (probably 0.x series) that did not support it. As for control enable - please run the debug version to make sure you have set the configuration correctly so it will show the flags that were recognized. Also note that if you use user authentication you have to specify the users that are allowed to issue control commands (see the docs).Fawn
so sorry, but took me some time to come back to this. Yeah you were right, I had installed the 0.x series. Many thanks, this was very helpful.Padgett
K
1

Yes you can. Always remember this:

R> fortunes::fortune("Yoda")

Evelyn Hall: I would like to know how (if) I can extract some of the information 
             from the summary of my nlme.
Simon Blomberg: This is R. There is no if. Only how.
   -- Evelyn Hall and Simon 'Yoda' Blomberg
      R-help (April 2005)

R> 

Or as the documentation for Rserve states:

\description{ Starts Rserve in daemon mode (unix only).

Any additional parameters not related to Rserve will be passed straight to the underlying R. For configuration, usage and command line parameters please consult the online documentation at http://www.rforge.net/Rserve. Use \code{R CMD Rserve --help} for a brief help.

Kerrin answered 25/11, 2012 at 18:8 Comment(4)
I am really sorry, but this does not help me at all (I did read the entire RServe documentation). Maybe it's just because I don't know how to pass a source-command 'straight to the underlying R'. I tried adding the the source commands to the Rserve.conf with no result. I created a .Rprofile and but then the source commands are still called everytime I create a new RConnection. Plus, .Rprofile is not loaded when I let Rserve be started by a start-stop-script.Padgett
Sorry, forget about the not working .Rprofil when starting the daemon by a start-stop-script. That was my fault.Padgett
We should maybe edit the question and/or answer to record one easily working way. What did you pick? RHOME/etc/Rprofile ? A per-startup-directory .Rprofile ?Kerrin
I edited my question making the possible solutions hopefully clearer.Padgett

© 2022 - 2024 — McMap. All rights reserved.