Data Communication Between R and Java using JRI

Introduction

This page describes how to install the eclipse plugin that helps calling R from Java using JRI. It is possible to transfer data between R and Java. In this tutorial we look at the objects in java that hold data returned from R.

RBool

RBool holds the boolean value. R boolean can take three states – true, false and NA. RBool has three methods isNA(), isTRUE() and isFALSE(). Here’s an example that shows how to get the return value from R into RBool

RFactor

RFactor stores the R factor variables. factors in R are used to store categorical values. Here’s an example of factors in R

This is how we do it from java

RList

RList is of type entry=value. The entry is stored in “head” and the value is stored in “body”. It is possible to retrieve body for a particular head using the method at(String).

To get the value’s string or number, use the asInt(), asString() or asDouble() method on the value object. The type can be obtained using the getType() method.

RVector

RVector represents the named generic vectors in R. It has all methods that java.util.Vector has plus methods at() and at(String)

REXP

If none of the above solves your problem, then look at REXP. This encapsulates all R objects. RList, RVector, RBool and RFactor have all been converted from REXP, however, if you need final control then this is your class.

4 thoughts on “Data Communication Between R and Java using JRI

    1. An Easy way to handle images and plots are to let R create the plot in a directory and let java read from that directory. There is no need to pass the image from R to java. R has graphic devices for jpg, png etc.

    2. Do you have a specific use case where creating an image file in R and just reading that file in Java would not solve the problem?

  1. Do you have an example where in java you are reading in an R function and the parameter of the R function is a file? Is this possible with rJava.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to top
Bitnami