R, loading rJava error

巧了我就是萌 提交于 2019-11-27 23:56:31

It works!

After installing and reinstalling different java versions and reinstalling rJava with the R command install.packages("rJava") I got to the point where loading the library in the R console (shell window) didn't throw an error message anymore.

After that I was able to use the answer in this post to get it to work in RStudio by running this shell command:

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

Not too complicated after all! Thank you for everyones patience.

JAVA_HOME path is different for different version of MAC OS. In some cases there is /jre folder and in some cases it is not after /Home director manually go towards /server folder with CD command in terminal and using pwd copy the entire path use that to set the java.home then you can easily load rJava library. This is how I was able to fix the issue

options("java.home"="/Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home/lib")

Sys.setenv(LD_LIBRARY_PATH='$JAVA_HOME/server')

dyn.load('/Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home/lib/server/libjvm.dylib')

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