How to Run an R Program from Java

How do you run an R program from Java?

You might want to take a look at these three projects.

  • JRI - Java/R Interface

  • Rserve

  • RCaller

calling R script from java

You just want to call an external application: wouldn't the following work?

Runtime.getRuntime().exec("Rscript myScript.R"); 

Run R script using JAVA program

You just want to call an external application: wouldn't the following work?

Runtime.getRuntime().exec("Rscript myScript.R"); 

Credit goes to stackoverflow itself

How to run R script from java using Process builder

The constructor of ProcessBuilder takes not the command line, but the command and its arguments. So, in this example it should be constructed as

new ProcessBuilder(userPrefs.get("PathToR",null), pt);

This builder will run R with single argument pt. Notice, that even if pt contains spaces, it will be interpreted as a single argument.



Related Topics



Leave a reply



Submit