rJava load error in RStudio/R after “upgrading” to OSX Yosemite

前端 未结 18 1777
Happy的楠姐
Happy的楠姐 2020-11-22 04:23

I recently \"upgraded\" from OSX Mountain Lion to Yosemite and from R 3.1.3 to 3.2. Immediately after the upgrade, when I opened R or RStudio I got a pop-up message saying t

相关标签:
18条回答
  • 2020-11-22 05:11

    I noticed that 'rJava' is pretty strict about JDK version while loading in Rstudio.
    In my case (Mac OS. 10.14.6 - Mojave) I had installed jdk-13 which was tested against jdk-11.
    I have linked my JDK version to a non-existent directory that was assumed to be valid by Rstudio (JDK 11):

    sudo ln -sf /Library/Java/JavaVirtualMachines/jdk-13.jdk/ /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk
    

    and suprisingly it works like a charm...
    BTW., there was no problem to run 'rJava' following the previous instructions in native R.

    0 讨论(0)
  • 2020-11-22 05:12

    You can load the libjvm.dylib explictly, by run like

    dyn.load('/Library/Java/JavaVirtualMachines/jdk1.8.0_66.jdk/Contents/Home/jre/lib/server/libjvm.dylib')
    library(rJava)
    
    0 讨论(0)
  • 2020-11-22 05:13

    You can change the reference in R by using the following command:

    sudo install_name_tool -change /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home/lib/server/libjvm.dylib /Library/Java/JavaVirtualMachines/jdk-13.0.1.jdk/Contents/Home/lib/server/libjvm.dylib /Library/Frameworks/R.framework/Versions/3.6/Resources/library/rJava/libs/rJava.so
    
    0 讨论(0)
  • 2020-11-22 05:15

    Following command works:

    sudo ln -s $(/usr/libexec/java_home)/jre/lib/server/libjvm.dylib /usr/local/lib
    

    After that, in RStudio, loading rJava works through loading of the "xlsx" package.

    library("xlsx")
    

    P.S. #1 Environment: Mac OS X El Capitan 10.11.3+ with RStudio 0.99.491+ and R 3.2.3+. (I've now tested this also on macOS Sierra (10.12) and R.3.3.1.)

    P.S. #2 I find that openxlsx is much faster and doesn't rely on Java to work, so I'm now using that package. Hope that helps others.

    0 讨论(0)
  • 2020-11-22 05:17

    This is how I configured it working properly on two Macs running Mac OS X El Capitan (10.11.6):

    1. Uninstall 'rJava' by issuing the following commands in a terminal window:

      Rscript -e 'remove.packages("rJava")'
      sudo Rscript -e 'remove.packages("rJava")'
      
    2. Download and install the Java software from Oracle: https://www.java.com/en/download/mac_download.jsp

    3. Add the following lines to /Users/<userid>/.bashrc using your favorite editor:

      # Set JAVA_HOME so rJava package can find it
      export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)/jre
      
    4. Close and restart any terminal, R, and RStudio windows (to pick up the changes to .bashrc).

    5. Run the following command in a Terminal window:

      sudo ln -sf $(/usr/libexec/java_home)/jre/lib/server/libjvm.dylib /usr/local/lib
      
    6. Run the following command in a Terminal window:

      sudo Rscript -e 'install.packages("rJava", repos="http://rforge.net", type="source")'
      
    0 讨论(0)
  • 2020-11-22 05:17

    Here what worked for me on MAC:

    1. in your ~/.profile or ~/.bashrc add this line: %export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home

      1.1 % source .profile (or % source .bashrc)

    2. % sudo ln -s $(/usr/libexec/java_home)/jre/lib/server/libjvm.dylib /usr/local/lib
    3. remove.packages(rJava)
    4. remove.packages(Rweka)
    5. From the terminal enter this command: %sudo R CMD javareconf
    6. install.packages("rJava", dependencies = TRUE, type = "source")
    7. install.packages("rJava", dependencies = TRUE, type = "source")
    8. Load your library("rJava", "RWeka")

    Best of luck.

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