Cannot load rJava because cannot load a shared library

后端 未结 6 496
陌清茗
陌清茗 2020-12-31 13:53

I have been struggling to load the rJava package in R.

I get the following messages

> library(rJava)
Error in inDL(x, as.logical(local), as.logic         


        
相关标签:
6条回答
  • 2020-12-31 14:35

    After editing your post for readability / formatting it seems that you have no Java system in your path. I don't use the OS you're trying to use this on, but on mine rJava only works if I also install a Java Run-Time Environment or, better still, a Java SDK.

    Note that the package clearly lists

    SystemRequirements: java
    

    and that the rJava site clearly states the following

    Installation

    First, make sure you have JDK 1.4 or higher installed (some platforms require hgher version see R Wiki). On unix systems make sure that R was configured with Java support. If not, you can re-configure R by using R CMD javareconf (you may have to prepend sudo or run it as root depending on your installation - see R-ext manual A.2.2 for details). On Windows Java is detected at run-time from the registry.

    rJava can be installed as any other R package from CRAN using install.packages('rJava'). See the files section in the left menu for development versions.

    JRI is only compiled if supported, i.e. if R was configured as a framework or with --enable-R-shlib.

    so I think we have a few smoking guns pointing the same way.

    0 讨论(0)
  • 2020-12-31 14:40

    If you have read this threat and neither of the suggestions above has worked so far, then it might be worth trying one further:

    • Windows 7
    • R version 2.12.1 (2010-12-16) 64-bit
    • Java(TM) SE Runtime Environment (build 1.6.0_23-b05), Java HotSpot(TM) 64-Bit Server VM (build 19.0-b09, mixed mode)

      JAVA_HOME=C:\Program Files\Java\jre6\bin\

      Path= ...;C:\Program Files\Java\jre6\bin\server\;C:\Program Files\R\R-2.12.1\bin\x64\

    The thing that finally solved my problem was to explicitly add \server\ to the PATH variable.

    0 讨论(0)
  • 2020-12-31 14:43

    Following up on some of Dirk's sage advice:

    • Your path should probably say C:\Program Files\Java\jre6\bin\ (remove "client").
    • Your path should also have C:\Program Files\R\R-2.10.1\bin\. You don't need that explicit reference to the rJava libs. I would also then remove C:\Program Files\R from the path.
    • Lastly, confirm that Java is accessible by either going to your command prompt and typing java -version, or from within R by typing system("java -version").
    • If you install the SDK, then you will also want a system variable JAVA_HOME which in my case points to C:\Sun\SDK\.
    0 讨论(0)
  • 2020-12-31 14:43

    System information: R version 3.0.1 (2013-05-16) Platform: x86_64-w64-mingw32/x64 (64-bit)

    I encountered this same problem. I was able to solve the issue with one line of code into the command window obtained from this website.

    Sys.setenv(JAVA_HOME='C:\Program Files\Java\jre7')

    Note that I used this particular line because I was on a 64 bit system. See website for 32-bit example.

    0 讨论(0)
  • 2020-12-31 14:49

    For what it's worth, putting C:\Program Files\Java\jre6\bin\[server] in my PATH worked for me. It seems the rJava module could jot find jvm.dll there.

    Here are the versions of R and Java that I'm using (on 64-bit Windows 7).

    Java:

    java version "1.6.0_30"
    Java(TM) SE Runtime Environment (build 1.6.0_30-b12)
    Java HotSpot(TM) 64-Bit Server VM (build 20.5-b03, mixed mode)
    

    R:

    R version 2.14.1 (2011-12-22)
    Copyright (C) 2011 The R Foundation for Statistical Computing
    ISBN 3-900051-07-0
    Platform: x86_64-pc-mingw32/x64 (64-bit)
    
    0 讨论(0)
  • I had a similar error and had to do an additional fix: Setting the R path explicitly to ...bin\x64, and also being consistent in using x64 Java and R.

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