2

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.

Paul
  • 1,325
  • 2
  • 19
  • 41
Sushant Gupta
  • 1,487
  • 2
  • 16
  • 23

3 Answers3

1

The script engine is planned for RCaller 3.0: http://mhsatman.com/rcallerscriptengine-a-scripting-interface-for-r-in-java-using-rcaller/

Tamas
  • 736
  • 2
  • 11
  • 27
  • Yes, it is true but the script engine will use RCaller Online in its background and path to R executable must be set before creating the engine. – jbytecode Apr 16 '16 at 23:10
  • Do you happen to know by when we may expect release 3.0? – Tamas Apr 17 '16 at 18:36
  • Since we have many decided features and code enhancements on the new version, we are working hard to prepare a reliable and modern library to satisfy needs of the Java community. As the key feature of RCaller is simplicity, we are also working to keep it as simple as we can. The excepted date is 15th May but it can be sooner. @Paul – jbytecode Apr 17 '16 at 20:39
  • Thank you a lot Paul and let me congratulate you on RCaller, it is a great tool! I also like the concept of simplicity very much. – Tamas Apr 19 '16 at 05:20
  • The script engine and the other new features are available now in version 3.0 : http://mhsatman.com/rcaller-3-0 – jbytecode May 09 '16 at 15:45
0

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.

Paul
  • 1,325
  • 2
  • 19
  • 41
jbytecode
  • 681
  • 12
  • 29
0

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.