简体   繁体   中英

Rcaller executing a function from .R file

I am trying to execute a R file from java, here is the code i have tried.

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

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. If there is anyother way to achieve this please suggest!

RCaller does not change the Java path format that is given in

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

to R format. This produces a R code like

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

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

defines the function with literally given R file as an R string.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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