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

◇◆丶佛笑我妖孽 提交于 2019-11-26 18:11:48

问题


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


回答1:


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)



回答2:


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.




回答3:


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.




回答4:


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



来源:https://stackoverflow.com/questions/9120270/how-can-i-install-rjava-for-use-with-64bit-r-on-a-64-bit-windows-computer

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!