rJava in RStudio, Windows, and library xlsx

This post is intended for users attempting to use the XLSX package in the Windows version of RStudio. I am using RStudio 0.98, R 3.1.2, Java 1.8.31 (all 64-bit).

I’m assuming you have R and RStudio installed, and have attempted to use the xlsx package in order to import data from the Microsoft Excel format. When I attempted to load this package, I get an error like this:

> library("xlsx", lib.loc="~/R/win-library/3.1")
Loading required package: rJava
Error : .onLoad failed in loadNamespace() for 'rJava', details:
  call: inDL(x, as.logical(local), as.logical(now), ...)
  error: unable to load shared object 'C:/Users/Charles/Documents/R/win-library/3.1/rJava/libs/x64/rJava.dll':
  LoadLibrary failure:  The specified module could not be found.

Error: package ‘rJava’ could not be loaded

First; make sure you have the 64-bit edition of Java installed. This solved the issue on my girlfriends computer, but not mine.

This nearly useless error message is due to the fact the system can’t locate jvm.dll. My solution was to append “;C:\Program Files\Java\jre1.8.0_31\bin;C:\Program Files\Java\jre1.8.0_31\bin\server” to my path variable. You *may* need to adjust that path if you’re using a different version of Java, but I’ll leave finding that to you (and if you don’t have Java installed, try that first).

THESE INSTRUCTIONS ARE FOR 64-BIT VERSION OF ALL SOFTWARE

Adding to the PATH variable

Open the “System” panel by hitting the windows key and pause|break at the same time (or right clicking on my computer->properties in Windows 7, or right clicking on the windows icon at the bottom left->system in Windows 8), then open “Advanced System Settings”

System Settings

In the System Properties window, go to the Advanced Tab, then click the “Environment Variables” button

Advanced System Settings

Search for the “Path” variable in the lower panel, the click edit

Edit path

And finally, append “;C:\Program Files\Java\jre1.8.0_31\bin;C:\Program Files\Java\jre1.8.0_31\bin\server” to the path and click OK

Append to path

And finally, relaunch RStudio. You should now be able to load the packages!