rscript - Java to R scripting interface
RForge.net

rscript

About rscript
SVN access
Download/Files

Description

Rscript is an implementation of Java 6 Scripting for R. (see also javax.script and JSR 223)

This allows R code to be run from a Java program in a standard manner. For example:

  ScriptEngineManager manager = new ScriptEngineManager();
  ScriptEngine engine = manager.getEngineByExtension("R");
  Object ret = engine.eval("print(1); 1");
  ret = ((Invocable)engine).invokeFunction("print", 2);

The engine supports the passing of boolean, integer, double and string objects and arrays too and fro between Java and R.

It uses either Rserve or JRI to communicate with R.

Usage

Common
Requires JRS.jar on the classpath.

The system property org.rosuda.jrs.host determines the default Rserve host to connect to or use JRI if not set.

Rserve
Also requires REngine.jar and RserveEngine.jar
Note: Rserve must also be running on the localhost (R CMD Rserve).
java -Dorg.rosuda.jrs.host=localhost -classpath JRS.jar:REngine.jar:RserveEngine.jar my.prog
JRI
Also requires JRI.jar and JRIEngine.jar and the jri JNI file (libjri.so, jri.dll, ...) and the R_HOME environment variable set (see the JRI FAQ).
java -Djava.library.path=jnidir -classpath JRS.jar:REngine.jar:JRI.jar:JRIEngine.jar my.prog

License

GPLv2 or Commercial

Author

Martyn Tebby (martyntebby@yahoo.com)