Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
426 views
in Technique[技术] by (71.8m points)

r - trouble installing and loading rJava on mac El Capitan

Have issue installing rJava, tried most troubleshooting steps here and doesn't work.

It's returning error

Loading required package: rJava
Error: package or namespace load failed for 'rJava':
 .onLoad failed in loadNamespace() for 'rJava', details:
 call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object     '/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/    rJava.so':

I'm on latest ver of R/Rstudio and Mac El Capitan

I also tried this method 1 which didn't work

sudo R CMD javareconf

Then, in the R interpreter:

install.packages('rJava', type='source')
install.packages('xlsx', type='source')

method 2

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

error returned ln: /usr/local/lib/libjvm.dylib: File exists

method 3 install.packages("rJava", type = "binary") error: tar: Failed to set default locale

to deal with default locale error

system("defaults write org.R-project.R force.LANG en_US.UTF-8")

upon loading rJava, still same error:

image not found

So looks like it's installed but won't load

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Here is my solution

Define path to R libraries, here R 3.4 version and open dir:

cd /Library/Frameworks/R.framework/Versions/3.4/Resources/lib

Remove libjvm.dylib:

rm libjvm.dylib

Create link to libjvm.dylib from Java libraries, here jdk1.8.0_151 version:

ln -s /Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/jre/lib/server/libjvm.dylib libjvm.dylib

now go to R or RStudio and try:

library("rJava")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...