What is the most efficient way to communicate with R (R Project), MySQL, and Java on a LAMP system?

StackOverflow https://stackoverflow.com/questions/22947010

Question

I am currently running a LAMP system (Linux Apache MySQL PHP). I have a data table stored in a MySQL database. I need to send this table to R (R project) which is currently installed and running on Apache. Then I need to send a long string formula to R which will be used to run a model (linear regression) on the data from MySQL. From there, I need to return the summary of the model from R back to MySQL.

Would it be beneficial to use one of the following?

  • Java servlet running on a webpage
  • Java servlet running on Apache Tomcat
  • Java Bean

Is there a better package to use for my situation? I've seen and read through the documentation for Rserve, JRI, and rjava. However, I'm having trouble deciphering which package would be better suited for my task.

Test Example using Rserve and a servlet running on a webpage:

RServeExample1.java:

import org.rosuda.REngine.REXP;
import org.rosuda.REngine.REXPMismatchException;
import org.rosuda.REngine.Rserve.RConnection;
import org.rosuda.REngine.Rserve.RserveException;

public class RServeExample1 {

public static void main(String[] args) throws RserveException, REXPMismatchException {
    RConnection c = new RConnection();
    REXP x = c.eval("R.version.string");
    System.out.println(x.asString());
}
}

After compiling the file, I uploaded the .class file to the server and added in the following HTML:

<APPLET CODE=RServeExample1.class WIDTH="150" HEIGHT="25"></applet>

When the webpage is opened, a java application error - RuntimeException is produced.

java.lang.reflect.InvocationTargetException

Am I implementing this in the wrong way?

Was it helpful?

Solution

Either Rserve or JRI would work. The key distinction is that Rserve separates the R logic from the rest of the application while JRI will include it in the application. I think the former would be the better option for your set up but the best way to figure out which is best is to test various scenarios that your application will run under and compare their performance.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top