Once Java is installed on a Windows based PC, one must ensure it is configured in the operating system in a way that R can access it. First, check the Java Control Panel. In the windows 10 search bar, search for Configure Java, and then press from the list of choices for the Java Control Panel.
From the Control Panel main window, select the Java tab,

and then press the button.
At this point you should see at least one row of information that illustrates the version and location where you have Java installed.

If your version of Java isn't listed, you can use the > or buttons to find or add the version that had been installed but is not listed.
Exit the Java Control Panel, open a command window (type cmd in Windows search bar), and type
java -version
This should display the version of Java that is visible to Windows, as illustrated below.

Next, we need to confirm that Java is accessible within RStudio. Open RStudio and use the system()
function to check the version of Java.
system("java -version")
We should receive the same result as we did with the Windows command line version of java -version
.
> system("java -version")
java version "1.8.0_231"
Java(TM) SE Runtime Environment (build 1.8.0_231-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.231-b11, mixed mode)
[1] 0
At this point, one should be able to install rJava
. However, if Java isn't accessible, we'll need to use the Sys.setenv()
function to set the path for Java home.
# set JAVA_HOME to directory listed in Configure Java app, such as
# C:\Program Files\Java\jre1.8.0_231
Sys.setenv(JAVA_HOME="C:/Program Files/Java/jre1.8.0_231")
...and now we should be able to install rJava.
install.packages("rJava")
> install.packages("rJava")
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.6/rJava_0.9-12.zip'
Content type 'application/zip' length 1214816 bytes (1.2 MB)
downloaded 1.2 MB
package ‘rJava’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\leona\AppData\Local\Temp\RtmpWGyEQp\downloaded_packages
>