Load “rJava” package on R
Recently, some R users (include myself) find that they are unable to load ‘rJava’ package in R. This creates a big headache to the regular R user, since ‘rJava’ package is a core dependent package for most of txt processing R packages, like xlsx, tabulizer, Rwordseg, etc.).
It is crucial to fix this issue and load ‘rJava’ package on R successfully. Therefore, I’ve spent some time to find a way to make it work. Here are the steps.
0.1 Step 1: Make sure your R version in the RStudio is 32-bit.
When the R is installed on the computer, it automatically installed 2 versions.
Both versions are good to use for regular R programming. However, some of the txt process packages, like Rwordseg, are only available in the 32-bit. Please set up your R in RStudio to 32-bit.
Go to RStudio, click:
Tools > Global Options > General，R version:
0.2 Step 2: Install or reinstall Java on your PC
Before install ‘rJAVA’ package, you need make sure that the java installed on your PC is the most up-to-date.
Remember: Install Java JDK, not the regular JRE.
You can find the download link below:
Download the setup file and install it on your computer (you may need seek help from IT department, since you may not have administrator authority for your computer). If it’s your personal computer, then never mind:)
Once the JDK installation process is complete, please check whether the installation is successful or not. In WIN10, follow the steps below.
- click ‘Search Window’ next to windows button
- type cmd to open command window
- type java -version then you’ll see the the version of JAVA displayed
0.3 Step 3: Find your java folder on your PC and configure path on your PC
On your computer, find the folder where your java is installed:
Configure path on your PC: click ‘Search Window’ next to windows button, then type cmd.
Look for “rundll32.exe sysdm.cpl,EditEnvironmentVariables”
Open a window, then add new User Variable-“JAVA_HOME” and put the Java path in the text dialog box (i.e., ‘C:Files (x86)1.8.0_161’, see below).
0.4 Step 4: Configure JAVA_HOME path on your RStudio
See the code block below.
You can also find the code below.