关于Java:在Rserve上仅一次搜索r文件

Sourcing r-files only once on Rserve

我写了一个小的Java客户端,它在Rserver上进行一些计算。为此,必须先获取服务器端的functions.r-和libraries.r文件,然后才能进行实际计算。

当前,我在每个新连接上加载文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
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();
  }  
}

其中doOnRserve()之所以被调用是由于在一分钟内客户端几次发生了一些事件。

我的问题是:是否有可能只提供一次库,这样它们就可以在所有新的RSession中使用而无需单独采购?

我在客户端尝试过类似以下内容:

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

哪个给了我以下异常(不知道为什么eval不能正常工作):

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

我可以使用特定的.Rprofile启动Rserve吗?

编辑:

基本上,接缝有三种可能的方法:

  • 让/home/rserve/.Rprofile作为.r文件的源。但是,这每次我调用new RConnection()时都可以获取它们的来源
  • 启动Rserve时将源命令直接传递给R(不知道如何执行此操作)。
  • 我的首选方法:使用serverSource()从客户端进行操作,这将引发这些"访问被拒绝"异常。
  • EDIT2:

    Rserve版本v0.6-8(338)

    用于x86_64-pc-linux-gnu的R版本2.15.2。


    这很简单,只需在配置文件中添加source行,即将

    1
    source"/foo/bar.R"

    /etc/Rserv.conf中的

    将在启动时提供/foo/bar.R。如果要使用另一个配置文件,请使用--RS-conf命令行参数来指定它。最后,Rserve 1.x在命令行上也支持--RS-source选项。

    在文件路径中没有引号,可能会显示"找不到文件"错误。

    BTW:您提到serverSource()访问被拒绝-这意味着您没有在Rserve中启用控制命令(配置中的control enable或命令行中的--RS-enable-control)。

    PS:请使用stats-rosuda-devel邮件列表来解决Rserve问题。


    是的,可以。永远记住这一点:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    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>

    或作为Rserve状态的文档:

    \\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.