How it works...

The .jinit() function initializes the Java Virtual Machine (JVM) and needs to be executed before invoking any of the rJava functions. If you encounter errors at this point, the issue is usually a lack of sufficient memory. Close unwanted processes or programs, including R, and retry.

For rJava to work, we need to sync up the Java version in the system environment with the rJava version. We used the .jcall("java/lang/System", "S", "getProperty", "java.runtime.version") command to get the Java version within the R environment.

After making sure that the Java versions are identical, the first thing we need to do, to access any Java object, is to set up classpath. We do this using .jaddClassPath. We pass the R working directory ...

Get R Data Analysis Cookbook - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.