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.
10 Comments. Leave new
SUPER. Thank you Joachim.
Thank you Robert, glad it was helpful! 🙂
thanks a lot, got the same issue. fixed easily using this
This is great to hear Sanchit, glad you found a solution!
thanks
You are very welcome Dennis!
Doesn’t work for me. I get:
“java.home option: PATH TO jre
JAVA_HOME environment variable:
Warning message:
In fun(libname, pkgname) :
Java home setting is INVALID, it will be ignored.
Please do NOT set it unless you want to override system settings.”
Hi Reinout,
It is difficult to help you with this error without seeing your code. Could you please share your code?
Regards,
Joachim
You are amasing ! Your page is always so helpful ! Thanks very much for this nice explanation ! I have to add, that I used this function because it offers the “showNA” parameter, so I’d like you to talk about it. It is not available in the “writexl” package, or the “openxlsx” package so I was getting empty cells.
Hello Maria,
Thank you for your kid words. I understand that you fixed your problem. If you have any further questions, don’t hesitate to ask.
Best,
Cansu