In case you tried loading a package that depends on the {rJava} package (by Simon Urbanek), you might came across the following error:
Loading required package: rJava
library(rJava)
Error : .onLoad failed in loadNamespace() for ‘rJava’, details:
call: fun(libname, pkgname)
error: JAVA_HOME cannot be determined from the Registry
The error tells us that there is no entry in the Registry that tells R where Java is located. It is most likely that Java was not installed (or that the registry is corrupt).
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.
Note that it is necessary to ‘manually download and install’ the 64 bit version of JAVA. By default, the download page gives a 32 bit version .
You can pick the exact version of Java you wish to install from this link. If you might (for some reason) work on both versions of R, you can install both version of Java (Installing the “Java Runtime Environment” is probably good enough for your needs).
(Source: Uwe Ligges)
Other possible solutions is trying to re-install rJava.
If that doesn’t work, you could also manually set the directory of your Java location by setting it before loading the library:
Sys.setenv(JAVA_HOME='C:\\Program Files\\Java\\jre7') # for 64-bit version
Sys.setenv(JAVA_HOME='C:\\Program Files (x86)\\Java\\jre7') # for 32-bit version
library(rJava)
(Source: “nograpes” from Stackoverflow, which also describes the find.java in the rJava:::.onLoad function)
Hallelujah! Thank you for helping me resolve this problem.
I’m very happy to read my post helped you 🙂
With regards,
Tal
The same for me!!! tks alot!!!
Helped me too!! I was trying other complicated solutions but none of them worked!
Thanks. 🙂
My pleasure 🙂
am getting below error while installing xlsx package, someone help me to get resolve.
* installing *source* package ‘xlsx’ …
** package ‘xlsx’ successfully unpacked and MD5 sums checked
** R
** inst
** preparing package for lazy loading
*** caught bus error ***
address 0x7ffe6dc79ef8, cause ‘non-existent physical address’
An irrecoverable exception occurred. R is aborting now …
/usr/lib64/R/bin/INSTALL: line 34: 33398 Done echo ‘tools:::.install_packages()’
33399 Bus error (core dumped) | R_DEFAULT_PACKAGES= LC_COLLATE=C “${R_HOME}/bin/R” $myArgs –slave –args ${args}
The downloaded source packages are in
Try rolling back to Java 1.6. That worked for me
You are the best! Thanks!
You’re welcome 🙂
To follow up on your point (and hopefully save others from frustration), it is necessary to ‘manually download and install’ the 64 bit version of JAVA. By default, the download page gives a 32 bit version as described here: http://java.com/en/download/faq/java_win64bit.xml.
Thanks David,
I’ve updated the post accordingly.
Thanks for your help !! Keep going !!
You’re welcome 🙂
Thank you, thank you, this was very helpful. (Needed to manually install 64 bit java for my script to work on a coworker’s windows machine) 🙂
You are welcome Woof 🙂
This was really helpful, thanks! When running from the command line I found it important to specific whether to run from /bin or /bin/x64. If Java is 64 bit, use the latter.
> Sys.setenv(JAVA_HOME=’C:Program FilesJavajre7′) # for 64-bit version
> Sys.setenv(JAVA_HOME=’C:Program Files (x86)Javajre7′) # for 32-bit version
> library(rJava)
Error : .onLoad failed in loadNamespace() for ‘rJava’, details:
call: inDL(x, as.logical(local), as.logical(now), …)
error: unable to load shared object ‘C:/Users/ryusukekenji/Documents/R/win-library/2.15/rJava/libs/x64/rJava.dll’:
LoadLibrary failure: %1 is not a valid Win32 application.
I am using 64bit windows, tried to install 64bit Java and also 32bit Java but keep giong error… May I know how to solve this problem?
Could you find the solution? I am in the same situation and cannot resolve.
Hey, I am also having toruble with the same issue. Anything which solves it? Had no issues running rJava before but now the same error message pops up after fixing the problem with the environment.
Thanks!!! Helped me a lot 🙂
Thanks! This helped!
My pleasure Arun 🙂
Bingo! Thanks… worked.
This helped me, but I kept getting Error: ‘\P’ is an unrecognized escape in character string starting “”C:\P”. I ended up having to use double \\ because \ is an escape character
Thank Kine,
You are of course correct.
The code was modified without my knowledge due to a recent change I made to the blog.
I fixed the code now to include “\\”
(p.s.: I checked an old cache of this page, and in it indeed the code was as it should be
http://web.archive.org/web/20140413084730/https://www.r-statistics.com/2012/08/how-to-load-the-rjava-package-after-the-error-java_home-cannot-be-determined-from-the-registry/
)
Thanks again,
Tal
Thank you so much! Finally someone who can explain a complicated-seeming topic in a very comprehensive manner – I´ve been trying to “uncode” the things that were written about changing directories and stuff on other pages but never was successful – now it worked out in 5 minutes! You save my day 😉
Thanks Anne. It makes me happy to know I was able to help 🙂
Best,
Tal
Thank you very much. My problem is solved.
Exact Solution!
Excellent!
Many Thanks …
Thanks a lot!
you are the angel! thanx!!
Thank gawd for people who post things like this. Bless you.
Wow this solved my problem. Thanks a lot!
I’m glad it helped 🙂
Thank you so much! I can finally write Excel files.
You’re welcome.
You may also wish to look at the readxl and openxlsx packages:
https://cran.r-project.org/web/packages/readxl
https://cran.r-project.org/web/packages/openxlsx
Thank you so much….it helped a lot.
Thank you a lot! With your instructions I successfully resolved this problem! 😉
Thank you ! Amazing I tried at least five options before!
for the commands
Sys.setenv(JAVA_HOME=’C:\\Program Files\\Java\\jre7′) # for 64-bit version
Sys.setenv(JAVA_HOME=’C:\\Program Files (x86)\\Java\\jre7′) # for 32-bit version
make sure that the path to your Java Jre is correct, for example in my Window OS the correct path is:
Sys.setenv(JAVA_HOME=’C:\\Program Files\\Java\\jre1.8.0_73′)
Tal, this is really helpful…crisp and clear! “Manually downloading and installing Java for 64-bit” is the key – atleast for me. Thanks much!!! 🙂
Great article. I was still unable to manually install the java 64-bit version. But used ninite.com
… http://www.cnet.com/forums/discussions/java-wont-install-on-my-windows-10-machine/
Once I got the 64 bit version of Java finally Installed, rjava loaded as well.
64Bit issue for me. You’re a lifesaver 🙂
My pleasure 🙂
Was of great help. Thank you!
Thank you, thank you, this was very helpful.
Very useful methods. I took nearly one day, fortunately all sorted out. Thanks so much.
Thanks a lot !
I detest this package. I’ve given up trying to use it, because the installation is incredibly complex, and leads to an endless series of errors. Whomever wrote this needs to have a step-by-step instruction guide.
Thanks! It worked for me
Thanks for this!
Hi,
Just a short note about what worked for me – Just adding the jdk path (instread of jre):
Sys.setenv(JAVA_HOME=’C:\\Program Files (x86)\\Java\\jdk1.8.0_121′)
Sys.getenv(‘JAVA_HOME’)
[1] “C:\\Program Files (x86)\\Java\\jdk1.8.0_121”
What to do when receiving message, “cannot determine a valid JAVA home?
Thnx a lot!
Thanks! it worked for me too!
Thanks a ton, worked like a charm.
I’m facing this issue with my Mac. But cannot find a Java 64bit download for Mac. Any workaround for this?
Installing a java in Window is quite easy, but after giving this Error it hard to fix this issues.Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. Personally i use Dell laptop having window 10 and and i was also getting this problem related to install the java then i went through https://www.delltechsupportnumbers.com/dell-alienware-support/
They helped me lot to fix my issues.
Struggled for 2 hours with this, got it working like a breeze…thank you
Thanks! Worked for me.
you are great, thanks! I have never been this close to throwing my laptop out the window. you saved it!