We have launched a free Basic Kubernetes Course. Click here to enrol now! Kubernetes is a container orchestration platform used by enterprises worldwide and Kubernetes developers are in high demand!
The R and Java eclipse Plugin helps in setting up the environment for running java applications that can invoke R using the rJava JRI library. It provides a preference window where the necessary paths need to be set. The steps below explain what paths need to be set and where you can find them. Note that this plugin has been tested only on windows, RJava on linux is easy!
R Jave Eclipse Plugin Download Link
Steps to Install R Java Eclipse Plugin
- Download the plugin using the link above.
- copy the plugin into the plugins directory of eclipse. ([Eclipse Home]/plugins/)
- Restart Eclipse
Setting up the R and Java Environment
- Install R. Install Java JRE/JDK if you have not done so already
- Install RJava using the R package installer.
- Install the plugin. Restart Eclipse
- Once the plugin is installed. Click on Eclipse->Preferences->RJava. Select the four directory paths using the browse button. The paths are explained below
- “Path to JRI DLL Dir” : This is the directory that contains jri.dll. When you install the rJava package, a folder called ‘rjava’ is created in the folder that stores all installed libraries in R. if you dont know where that is, open up R and fire the command ‘library()‘. This will open up another window that shows the path where the libraries are installed. Look for rjava. The line on the top gives the installation path. select the [rjava]/jri folder from the preference page. If your machine is 64 bit select [rjava]/jri/x64
- “Path to JRI JARS” : Select the [rjava]/jri folder. Make sure that this folder contains JRI.jar, JRIEngine.jar, REngine.jar. This path is generally same as the one above, unless you want to put the jars in a different location. If any of the above jar is missing then you can download them from here.
- “Path to R DLL Dir” : This specifies the path to R.dll. It should be present in R_Home/bin or R_home/bin/x64 for 64 bit machines.
- “Path to JVM DLL dir” : This specifies the path to jvm.dll. It should be present in JRE_HOME/bin/server or JRE_HOME/bin/client.
- Click on Apply and then OK. Now you are ready to create your first application.
First R and java Application
This is what you have been waiting for, your first RJava enabled application. Follow the steps below
- Create New Java Project.
- Right click on the Java project -> select ‘Build Path’ -> click ‘Add Libraries’.
- In the popup that comes up, select ‘User Library’ and click ‘Next’.
- you should see a library called ‘JRI_DIR’. select it and click Finish. You are now ready to write your first class. (If you don’t see the JRI_DIR then simply add the jars from [rjava]/jri/ to your classpath.)
- To test immediately, go to [rjava folder]/jri/examples/ and copy rtest2.java into the new project that you have just created. If it compiles correctly then the first phase is complete. Next we run it.
- To run a class that contain RJava code. Right click on the class->select ‘Run As’->Click on ‘Run Configurations’.
- In the run configuration window, there should be a run configuration that says ‘R’. select that and click on the ‘New Launch Configuration’ icon on the top. This will create a new launch configuration. Click on ‘Run’. That’s it!
- If you are using the 64 bit binaries, make sure you use the 64 bit binaries for both R and rjava.
- If you change the RJava preferences after creating the Runtime configuration, then delete the configuration and create a new one. The changed preferences are not visible in already created configurations
Do send us a mail at firstname.lastname@example.org if you are facing issues or drop in your comments about the plugin. Spread the word!!