Integrating R and Java

Do you want to use R and Java together? Renjin makes it very easy to integrate R and Java in three quick steps:

First, add Renjin as a dependency to your Maven project:


For this to work you will also need to add BeDataDriven’s public repository to your pom.xml:

        <name>bedatadriven public repo</name>

If you're not using Maven, you can find comparable instructions for all major JVM-based build tools in our Project Setup Guide

Once you have the dependency added, you can create a new RenjinScriptEngine:

    import javax.script.*;
    import org.renjin.script.*;

    // ... add additional imports here ...

    public class TryRenjin {
      public static void main(String[] args) throws Exception {
        // create a script engine manager:
        RenjinScriptEngineFactory factory = new RenjinScriptEngineFactory();

        // create a Renjin engine:
        ScriptEngine engine = factory.getScriptEngine();

        engine.eval("df <- data.frame(x=1:10, y=(1:10)+rnorm(n=10))");
        engine.eval("print(lm(y ~ x, df))");

That's it! You're now calling R from Java.

Visit our documentation for more details and advanced use cases.

Read more at Renjin's blog or subscribe to the blog's RSS feed.

Bring the Power of R
to Java

Ready to get started?

Quick start with Java Join our mailing list