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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.