Making the interface between R and Java work is not easy. There a few steps to do before it will work. These steps were necessary on OSX with NetBeans IDE:
- Edit the NetBeans config file
- Add libraries to your project
- Adjust run setting for the Java VM
Edit NetBeans config
This first step is necessary to export the R_HOME environment setting to get it working
- Find your R_HOME settings by typing ‘R.home()’ in R or RStudion. The path to R will then be printed out. For me it is: /Library/Frameworks/R.framework/Resources
- Then go to the NetBeans config file. You can get there by opening the Finder and then Applications. Open the Netbeans folder and then right-click on the netbeans app icon and select “show package content”. Then go to /Applications/NetBeans/NetBeans 8.0.1.app/Contents/Resources/NetBeans/etc/netbeans.conf
- Open the file with an editor (“textedit”).
- Add the following line at the end of the file
Another way to tell NetBeans the right directions to the R_HOME is to use the terminal app of OSX and use the “run script” to hand over the necessary information. More information on this topic can be found here.
To avoid classpath confusion you have to add JAR files to your project.
At first you have to download the JAR files. The best way to do this is to install the packages “rJava” and “JAVAGD” directly in R with the R console or RStudio. You will find the JARs the in the following folders on your computer:
JRI will be in /Library/Frameworks/R.framework/Versions/2.15/Resources/library/rJava/jri
Add the following JAR files to your project by right-clicking the package of your project in NetBeans and the selecting “Add JAR”:
Java VM settings
Finally go to the menu category “Run”:
In VM-Options you have to add the following line: