Close Navigation
Learn more about IBKR accounts
Using R Code in Java Eclipse with rJava

Using R Code in Java Eclipse with rJava

Posted March 10, 2023
Sang-Heon Lee
SHLee AI Financial Model

This post shows how to use R code in Eclipse IDE for Java with rJava package. But this work requires several environment setting which is a little bit confusing. Although there are some good posts regarding this issue, we use a step by step guide with detailed screen captures for clear understanding.

Introduction

Occasionally we would encounter some problems which are not easy to implement in Java. Among them are financial or econometric model estimation or optimization, to name a few. But in many cases, these problems are easily solved in R thanks to its various packages which are supported by worldwide experts.

This leads to the necessity of the connection between R and Java. For this purpose, rJava package provides this interface functionality but environment setting is not easy.

With detailed screen captures, let’s find the efficient way to use rJava in Eclipse. For convenience, we assume R and Eclipse are installed already.

Installing rJava

We need to install rJava package in R studio.

We need to know the directory where rJava package is installed. In our case, this directory is as follow. (this is dependent on your Windows system)

C:\Users\shlee\Documents\R\win-library\4.0

The following figure displays files of rJava/jri directory.

Environment Variables

Find “Edit the system environment variables” and open System Properties box, and click Environment Variables … button.

Add Path as a new variable in System Variables as follows.

  • Path : C:\Users\shlee\Documents\R\win-library\4.0\rJava\jri\x64;

Eclipse Project and Class

Make a new project in Eclipse : File -> New -> Java Project .

Insert aRjava or your favorite name as Project name.

  • Project name : aRjava

Make a new class : File -> New -> Class .

Insert CRjava or your favorite name as Name.

  • Name : CRjava

Visit SH Fintech Modeling Blog for instructions on how to write a Java code with rJava and to read the full article.

Disclosure: Interactive Brokers

Information posted on IBKR Campus that is provided by third-parties does NOT constitute a recommendation that you should contract for the services of that third party. Third-party participants who contribute to IBKR Campus are independent of Interactive Brokers and Interactive Brokers does not make any representations or warranties concerning the services offered, their past or future performance, or the accuracy of the information provided by the third party. Past performance is no guarantee of future results.

This material is from SHLee AI Financial Model and is being posted with its permission. The views expressed in this material are solely those of the author and/or SHLee AI Financial Model and Interactive Brokers is not endorsing or recommending any investment or trading discussed in the material. This material is not and should not be construed as an offer to buy or sell any security. It should not be construed as research or investment advice or a recommendation to buy, sell or hold any security or commodity. This material does not and is not intended to take into account the particular financial conditions, investment objectives or requirements of individual customers. Before acting on this material, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice.

IBKR Campus Newsletters

This website uses cookies to collect usage information in order to offer a better browsing experience. By browsing this site or by clicking on the "ACCEPT COOKIES" button you accept our Cookie Policy.