Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java-R integration?

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?

like image 272
mbatchkarov Avatar asked Sep 17 '11 00:09

mbatchkarov


People also ask

Can we integrate R with Java?

Rserve can be used to execute R code on a remote server. FastR allows seamless integration with Java but makes our code dependent on the VM and is not available for every OS.

Why do we use R in Java?

'\r' is the representation of the special character CR (carriage return), it moves the cursor to the beginning of the line. '\n'(line feed) moves the cursor to the next line . On windows both are combined as \r\n to indicate an end of line (ie, move the cursor to the beginning of the next line).

What is the use of T in Java?

What does \t mean in Java? This means to insert a new tab at this specific point in the text. In the below example, "\t" is used inside the println statement. It is similar to pressing the tab on our keyboard.


2 Answers

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

like image 63
Guido Avatar answered Sep 29 '22 12:09

Guido


There has been work by Duncan Temple Lang: http://rss.acs.unt.edu/Rdoc/library/SJava/Docs/RFromJava.pdf .

My guess as to the most robust solution would be JGR. The developers of JGR have a mailing list, Stats-Rosuda and the mailing list Archive indicates the list remains active as of 2013.

There is also code that has been put up at Googlecode, with an example here: http://stdioe.blogspot.com/2011/07/rcaller-20-calling-r-from-java.html

like image 36
IRTFM Avatar answered Sep 29 '22 12:09

IRTFM