简体   繁体   中英

How to call R Script file from RCaller java?

My project has some R files prebuilt and I need to invoke them from Java layer .

I cannot figure out a way to provide RScript file path to RCaller .

Need help to call RScript file from RCaller Java .

脚本引擎计划用于RCaller 3.0http : //mhsatman.com/rcallerscriptengine-a-scripting-interface-for-r-in-java-using-rcaller/

If you use Linux , the path for RScript is /usr/bin/Rscript . In Windows , it depends on the version of R , but you can find its location using the file browser and it follows a pattern similar to C:\\\\Program Files\\\\R\\\\R-3.0.2\\\\bin\\\\Rscript.exe in a standard installation.

Addition to this, after detecting the path you can set it using

caller.setRscriptExecutable(pathToRscript);

if you want to get only one result per run and you can set the R location using

caller.setRExecutable(pathToR);

for online calculations, that is, if you perform calculations sequentially in a send-eval-get loop.

If you want your code to find out the path automatically, you can perform a recursive find for RScript and R executables . In an other way, using a FileDialog GUI object, you can let the user find himself.

Now there are few other ways to call R Script from RCaller. After setting the Rscript Executable path. Using your RCode object(code) simply add code as-

code.addRCode("source('yourRscript.R')");

Or, you can directly call youRscript by the method

code.R_source("pathtoyouRscript");

then run your code from RCaller object using runOnly() command.

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