Using JRI to call R functions from Java

The JRI allows you to execute R commands inside Java applications as a single thread. JRI loads R libraries into Java and thus provides a Java API to R functions.

Getting ready

Make sure all the steps in the earlier recipe Using Java objects in R are completed.

How to do it...

To use JRI to call R functions from Java, follow these steps:

  1. Set up environment variables R_HOME to where R has been installed and add the R bin directory to the environment variable PATH.
  2. Open a new terminal window (on OS X and Linux systems) or open a command prompt window on Windows. Make sure to change the values according to your environment. The following commands help to set up environment variables on OS X and Linux systems. Make ...

Get R: Recipes for Analysis, Visualization and Machine Learning now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.