简体   繁体   English

Rcaller从.R文件执行功能

[英]Rcaller executing a function from .R file

I am trying to execute a R file from java, here is the code i have tried. 我正在尝试从Java执行R文件,这是我尝试过的代码。

RCaller caller = new RCaller();
RCode code = new RCode();  
caller.setRscriptExecutable("D:\\R\\R-3.0.2\\bin\\Rscript.exe");    
code.clear();
caller.setRCode(code);
code.R_source("D:\\Data\\Workspace\\Cpackage\\try.R");
caller.setRCode(code);
caller.runOnly();

try.R file try.R文件

myinput<-function(){
//loading a csv file,reading it and creating an excel file(Working when it is run from r directly)
}

myinput()

The above rcaller java code does not do anything.Please help if i am doing anything wrong,i need to do this very badly. 上面的rcaller java代码不执行任何操作。如果我做错任何事情,请提供帮助,我需要做得很差。 If there is anyother way to achieve this please suggest! 如果还有其他方法可以实现,请提出建议!

RCaller does not change the Java path format that is given in RCaller不会更改中给出的Java路径格式

code.R_source("D:\\Data\\Workspace\\Cpackage\\try.R");

to R format. 到R格式。 This produces a R code like 这会产生一个R代码,例如

source("D:\\Data\\Workspace\\Cpackage\\try.R")

so you need to change it to 所以你需要将其更改为

code.R_source("D:/Data/Workspace/Cpackage/try.R");

It is good to have a look at the source code at Rcaller source , it can be seen that 最好在Rcaller源代码中查看源代码 ,可以看出

public void R_source(String sourceFile) {
    addRCode("source(\"" + sourceFile + "\")\n");
}

defines the function with literally given R file as an R string. 用字面意义上的R文件将函数定义为R字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM