I am trying to load the rJava using the command:
library(rJava)
But I get the following error:
Error : .onLoad failed i
This error is often resolved by installing a Java version (i.e. 64-bit Java or 32-bit Java) that fits to the type of R version that you are using (i.e. 64-bit R or 32-bit R). This problem can easily effect Windows 7 users, since they might have installed a version of Java that is different than the version of R they are using.
http://www.r-statistics.com/2012/08/how-to-load-the-rjava-package-after-the-error-java_home-cannot-be-determined-from-the-registry/
I faced the same issue and was feeling very down as I couldnt get my analysis done. This worked for me :
check your operating system. 64 bit or 32 bit. https://helpx.adobe.com/x-productkb/global/determine-whether-computer-running-32.html
uninstall previous versions of Java.
delete rJAVA library from Doc>R>win-library. If you have more than 1 versions of R, make sure you delete rJAVA package from all of them.
install Java based on system requirement (64 bit or 32 bit).
and finally restart R before and after installing rJava package.
R for Windows installer installs by default both 32-bit and 64-bit files. Reinstalling R and unticking 32-bit part solved the problem for me.
If R is 64-bit version make sure to install Java 64-bit version!
If R is x86-bit version make sure to install Java x86-bit version!
As mentioned in the r-statistics link cited above, you have to manually download the 64-bit version of Java. If not, then the 32-bit version will be installed.
So, if you have a 64-bit operating system, then ensure that both R and Java are using the 64-bit installs. Otherwise, this problem will persist.
This has been killing me and I have tried multiple methods above, it doesn't work. After, I mix all solution to try and below process works for me.
setx PATH "C:\Program Files\Java\jre1.8.0_171\bin\server;%PATH%"
Sys.setenv(JAVA_HOME="")
library(rJava)
library(xlsx)