How can I install rJava for use with 64bit R on a 64 bit Windows computer?
Asked Answered
C

4

25

I installed iplots and rjava packages. When I do this library(iplots), I get the following error. I do have JDK installed on my pc.

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

Error: package ‘rJava’ could not be loaded

Colorfast answered 2/2, 2012 at 21:27 Comment(0)
S
35

The error is telling you that there is no entry in your Registry that tells R where Java is located on your machine. Either your registry is corrupt, but more likely you haven't installed Java. You can install either the Java Runtime Environment or the Java Development Kit.

(You can download Java here.)

If you installed Java, try reinstalling it. This should put the entries back in your Registry.

If that doesn't work, you can start looking at exactly where R is looking for your Registry entries. The function that rJava uses to find Java is in the rJava:::.onLoad function. Within that function there is a subfunction called find.java. I copy the contents here:

    find.java <- function() {
        for (root in c("HLM", "HCU")) for (key in c("Software\\JavaSoft\\Java Runtime Environment", 
            "Software\\JavaSoft\\Java Development Kit")) {
            hive <- try(utils::readRegistry(key, root, 2), 
              silent = TRUE)
            if (!inherits(hive, "try-error")) 
              return(hive)
        }
        hive
    }

Copy and paste this into your R window, and then run it find.java(). rJava is looking for an entry for JavaHome. If that isn't listed, then it is missing from your registry.

You could also manually set the directory of your Java location by setting it before loading the library:

Sys.setenv(JAVA_HOME='C:\\Your\\Java\\Directory')
library(rJava)
Sipple answered 2/2, 2012 at 22:5 Comment(5)
The above is correct. In addition, note that you will need matching architectures for R and Java (if you are on 64-bit Windows). As a last resort you can set JAVA_HOME to point to your Java installation, but typically the above means that there is something wrong with your Java installation.Labonte
JDK is installed on my pc.java -version java version "1.6.0_20" Java(TM) SE Runtime Environment (build 1.6.0_20-b02) Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode, sharing)Colorfast
I made some additions in my answer.Sipple
@SimonUrbanek: very helpful comment. Thanks! I was wondering why my 64-bit R can't find my newly installed Java, but it seems that 32-bit Java is downloaded by default. You'll need to manually find the 64-bit Java on their home page.Idden
To follow up on @SimonUrbanek's point, (and hopefully save others from frustration), it is necessary to 'manually download and install' the 64 bit version of JAVA from here. By default, the main download page gives a 32 bit version even on 64 bit machines as described and justified in the Windows FAQPouf
T
3

If like me you do not have admin rights to install 64-bit Java, just open 32-bit R and it should work ok on your 64 bit PC as part of the problem seems to be the rJava library function calls embedded Java functions/routines, which may only have being designed for 32-bit interface with Excel/Windows and possibly too large a task at the time to change everything.

Thornton answered 30/12, 2015 at 11:13 Comment(0)
M
1

Answer in link resolved my issue.

Before resolution, I tried by adding JAVA_HOME to windows environments. It resolved this error but created another issue. The solution in above link resolves this issue without creating additional issues.

Michelle answered 7/3, 2016 at 12:12 Comment(0)
P
0

Any Linux users here, run command:

sudo R CMD javareconf

That typically needs to be run after an update of the system Java installation, as suggested here

Pianola answered 26/8, 2019 at 16:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.