Using Java objects in R
Sometimes, we develop parts of an application in Java and need to access them from R. The rJava package allows us to access Java objects directly from within R.
Getting ready
If you have not already downloaded the files for this chapter, do it now and ensure that these files are in your R working directory:
- Create a folder called
javasamples, and move all the files with extension.javaor.classinto this folder under your working directory. - Install
rJavausing theinstall.packages("rJava")command. - Load the package using the
library(rJava)command. - For
rJavato work in your environment, the JDK version should be identical for the following, and we explain how to get them in sync for Mac OS X:
- The environment JDK version: Execute
java -versionin your command line to get the installed version of Java. You will be using this version to create the.jarfiles or to compile Java programs. - The JDK version in R: After you install and load the
rJavapackage, check the JVM version...
- The environment JDK version: Execute