R and Java – JRI using eclipse.

[This article was first published on R – StudyTrails, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Update – Check out the new RJava Eclipse Plugin.
R is a powerful language for statistical computing and graphics. R has a strong community support and is finding new use in the corporate world. If R can be integrated with Java, it would provide a greap acceptance into new products. A library called rjava exists that helps integrate R with Java. However, setting up the library may be tricky.

This post explores how R can be called from within Java using JRI. We will use the example provided in the rjava package. The example class is called rtest2.java.

Here are the steps to run R from java using eclipse.

1) Create a new project and copy the rtest.java and rtest2.java files from the rjava/jri package. The rjava project folder can be found at the place where R stores the package downloaded during the install step. It should be in a folder called ‘win-library’.

2) the rjava/jri folder in ‘win-library’ should also have the JRI.jar library and jri.dll file. copy R.dll from the bin directory of R into the rjava/jri folder.
Here’s the folder hierarchy for JRI

3) add the JRI.jar in the project classpath in eclipse

4) Add the following entries into the run configuration of the product.

THe path variable contains
C:/Users/user/Documents/R/win-library/2.9/rJava/jri/;C:Program FilesRR-2.9.1bin

That’s it. This should work. Run the rtest2 file and you should see R working.

Some of the steps above may not be required. However, i have found this to be working after some research and would not like to experiment further. Please add your comments if it works and also if it does not.

To leave a comment for the author, please follow the link and comment on their blog: R – StudyTrails.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)