Java-R integration?

mbatchkarov picture mbatchkarov · Sep 17, 2011 · Viewed 49.3k times · Source

I have a Java app which needs to perform partial least squares regression. It would appear there are no Java implementations of PLSR out there. Weka might have had something like it at some point, but it is no longer in the API. On the other hand, I have found a good R implementation, which has an added bonus to it. It was used by the people whose result I want to replicate, which means there is less chance that things will go wrong because of differences in the way PLSR is implemented.

The question is: is there a good enough (and simple to use) package that enable Java to call R, pass in some parameters to a function and read back the results? My other option is to have Java spawn R in a Process and then monitor it. Data would be read and written to disk. Which of the two would you recommend? Am I missing the obvious third option?

Answer

Guido picture Guido · Sep 17, 2011

I have successfully used two alternatives in the past.

JRI

  • Pros: probably better performance.
  • Cons: you have to configure some environment variables and libraries, different in Win/UNIX.

RServe

  • Pros: easy to setup, you don't need to initialize R or link against any R library, can run in a different machine.
  • Cons: based on TCP/IP (a server is running), no callbacks from R.

Other alternatives I have never used : RCaller