簡體   English   中英

Rcaller從.R文件執行功能

[英]Rcaller executing a function from .R file

我正在嘗試從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文件

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

myinput()

上面的rcaller java代碼不執行任何操作。如果我做錯任何事情,請提供幫助,我需要做得很差。 如果還有其他方法可以實現,請提出建議!

RCaller不會更改中給出的Java路徑格式

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

到R格式。 這會產生一個R代碼,例如

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

所以你需要將其更改為

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

最好在Rcaller源代碼中查看源代碼 ,可以看出

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

用字面意義上的R文件將函數定義為R字符串。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM