R Error: JAVA_HOME cannot be determined from the Registry (Example)

 

This article shows how to handle the error message “JAVA_HOME cannot be determined from the Registry” in the R programming language.

The tutorial will contain these content blocks:

Let’s just jump right in.

 

Example 1: Reproducing the Error: JAVA_HOME cannot be determined from the Registry

In this example, I’ll explain how to replicate the error message “JAVA_HOME cannot be determined from the Registry”.

This error message typically appears when we want to load the xlsx package as shown below:

install.packages("xlsx")           # Install & load xlsx
library("xlsx")
# Loading required package: xlsx
# Loading required package: xlsxjars
# Loading required package: rJava
# Error : .onLoad failed in loadNamespace() for 'rJava', details:
#   call: fun(libname, pkgname)
#   error: JAVA_HOME cannot be determined from the Registry
# Failed with error:  'package 'rJava' could not be loaded'

As you can see, the error “JAVA_HOME cannot be determined from the Registry” was returned to the RStudio console after installing and loading the xlsx package.

However, this problem does not occur because of the xlsx package, but because of the rJava package.

R tries to install the rJava package as well, when we are installing the xlsx package.

So why does the error message “JAVA_HOME cannot be determined from the Registry” occur when we are trying to install the rJava package?

The reason for this usually is that you are using a 64-bit version of R, but not a 64-bit version of Java.

You may have installed a 32-bit version of Java or you might not have installed Java at all.

Note that the Java download page suggests the 32-bit version by default. Hence, it is necessary to manually install the 64-bit version.

 

Example 2: Fixing the Error: JAVA_HOME cannot be determined from the Registry

In this example, I’ll explain how to solve the problems when trying load an R package due to rJava.

For this, you have to download and install the 64-bit version of Java on this page: Download Java 64-bit version for Windows.

After installing the 64-bit version of Java, we have to install and load the rJava package (or as in our example the xlsx package) again:

install.packages("xlsx")           # Install xlsx package
library("xlsx")                    # Load xlsx package

This time it worked without any issues!

 

Video & Further Resources

Have a look at the following video which I have published on my YouTube channel. In the video, I’m explaining the content of this article in a live session in RStudio.

 

The YouTube video will be added soon.

 

Furthermore, you could read the related articles of my homepage:

 

In summary: You learned in this article how to fix the error “JAVA_HOME cannot be determined from the Registry” in R programming. If you have additional questions, don’t hesitate to let me know in the comments below.

 

Subscribe to the Statistics Globe Newsletter

Get regular updates on the latest tutorials, offers & news at Statistics Globe.
I hate spam & you may opt out anytime: Privacy Policy.


10 Comments. Leave new

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.

Top