Error while loading rJava

前端 未结 2 1782
误落风尘
误落风尘 2020-12-03 06:05

I get an error when I\'d like to load rJava. JDK is installed. (I run R on a CentOS VM (cloudera demo vm cdh3u4))

> library(rJava)

Error : .onLoad failed         


        
相关标签:
2条回答
  • 2020-12-03 06:44

    For Ubuntu, oracle-java (7/8) installed. It'll be at this location /usr/lib/jvm and sudo access is required.

    Create the file /etc/ld.so.conf.d/java.conf with the following entries:

    /usr/lib/jvm/java-8-oracle/jre/lib/amd64
    /usr/lib/jvm/java-8-oracle/jre/lib/amd64/server
    

    (Replace java-8-oracle with java-7-oracle or java-7-openjdk-amd64 depending on your java version)

    Then:

    sudo ldconfig
    

    Restart RStudio and then install the rJava package.

    0 讨论(0)
  • 2020-12-03 06:53

    Getting rJava to work depends heavily on your computers configuration. The following is working at least on a windows platform. You could try and check, if this will help you on your platform, too.

    1. You have to use the same 32bit or 64bit version for both: R and JDK/JRE. A mixture of this will never work (at least for me).
    2. If you use 64bit version make sure, that you do not set JAVA_HOME as a enviorment variable. If this variable is set, rJava will not work for whatever reason. You can check if your JAVA_HOME is set inside R with:

      Sys.getenv("JAVA_HOME")
      

    If you need to have JAVA_HOME set (e.g. you need it for maven or something else), you could deactivate it within your R-session with the following code before loading rJava:

    if (Sys.getenv("JAVA_HOME")!="")
      Sys.setenv(JAVA_HOME="")
    library(rJava)
    

    This should do the trick in most cases. Furthermore this will fix issue Using the rJava package on Win7 64 bit with R, too. I borrowed the idea of unsetting the enviorment variable from R: rJava package install failing.

    0 讨论(0)
提交回复
热议问题