R and Java – JRI using eclipse.

November 25, 2009

(This article was first published on R – StudyTrails, and kindly contributed to R-bloggers)

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 on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


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)