Java-R integration?
Asked Answered
D

8

56

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?

Doge answered 17/9, 2011 at 0:49 Comment(2)
Take a look at graalvm.orgDogwood
@Ashish Kumar - The link is deadAhasuerus
D
51

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

Dniren answered 17/9, 2011 at 15:20 Comment(1)
Have a look at this: github.com/subes/invesdwin-context-r It provides a simple Java API with multiple runtime implementations available to pick from. Thus you write your sripts once and just pick at runtime which integration to use. As each one has its own benefit/drawbacks as stated by Guido.Thicket
D
10

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

Dominions answered 17/9, 2011 at 14:47 Comment(2)
JGR is the GUI that, if I am not wrong, uses JRI under the covers.Dniren
I've seen it described as a method of calling R from Java by the developers of JGRDominions
C
8

This is an old question.. but for anyone browsing through here that is still interested: I wrote a blog article that provides a detailed example of how to use JRI/rjava (a JNI based bridge) to do this type of thing (the how-to is focused on Linux dev environments). I also compare and contrast alternative approaches for doing 'mathy' stuff by calling out to R and similar frameworks.

URL > http://buildlackey.com/integrating-r-and-java-with-jrirjava-a-jni-based-bridge/

Casting answered 21/10, 2013 at 23:48 Comment(0)
P
7

Renjin is an alternative that allows not only the integration of many packages of R also a easy going communication between Java and R through objects:

http://www.renjin.org/

Pamphlet answered 15/7, 2015 at 19:5 Comment(0)
D
3

JRI has both low level and High level interface to Call R from Java. There is an eclipse plugin that helps in setting up the R Java environment at http://www.studytrails.com/RJava-Eclipse-Plugin/.

Dismiss answered 5/1, 2013 at 11:47 Comment(1)
I followed all steps but unable to do last one: Add JRI_DIR. According to one commend ' you don't actually have to see the JRI_DIR, you just add the *.jar-s from [rjava]/jri/ and it works' but I'm unable to do it. What does this mean?Anxiety
M
3

This seems to be an old question. However Rserve and rJava are two good packages to integrate R with Java. Following blogs explain usage of both these libraries.

For rJava: http://www.codophile.com/how-to-integrate-r-with-java-using-rjava/

For Rserve: http://www.codophile.com/how-to-integrate-r-with-java-using-rserve/

I hope this will help.

Meunier answered 13/5, 2015 at 9:16 Comment(0)
L
1

I had similar need a while back and tested a few of the interfaces to R. The one I found to be the best for my needs (windows, c#) was Rserve which I believe is written in Java. My only gripe with it is that it wasn't 64-bit. I used a simple client written in c# and it worked very well. I'm sure the Java client is a lot better.

Luteal answered 17/9, 2011 at 7:22 Comment(0)
M
1

FastR is a GraalVM based implementation of R. Embedding it in a JVM application is as simple as:

Context ctx = Context.newBuilder("R").allowAllAccess(true).build();
ctx.eval("R", "sum").execute(new int[] {1,2,3});

More details in this article: https://medium.com/graalvm/faster-r-with-fastr-4b8db0e0dceb

Monotony answered 11/10, 2018 at 20:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.