r.java 错误,R,加载rJava错误

I'm running R (version 3.4.0) on macOS sierra (10.12.5) and I'm trying to use the xlsx library which requires the use of the rJava library.

When I try to load rJava using library(rJava) in the R console (no difference if in RStudio or in the terminal), I get the following error message which I'm having trouble making sense of:

Fehler: package or namespace load failed for ‘rJava’:

.onLoad in loadNamespace() für 'rJava' fehlgeschlagen, Details:

Aufruf: dyn.load(file, DLLpath = DLLpath, ...)

Fehler: kann shared object '/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/rJava.so' nicht laden:

dlopen(/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/rJava.so, 6): Library not loaded: @rpath/libjvm.dylib

Referenced from: /Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/rJava.so

Reason: image not found

Googling the problem I found a number of posts on somewhat similar (but each time slightly different problems), this SO question being the most promising among them.

Since the steps of the proposed require adaptation to my case and I'm kind of a novice, I wasn't able to implement them. What can I do?

Additional information:

The shell command java -version returns:

java version "1.8.0_131"

Java(TM) SE Runtime Environment (build 1.8.0_131-b11)

Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

And the shell command R CMD javareconf returns:

Java interpreter : /usr/bin/java

Java version : 1.8.0_131

Java home path : /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre

Java compiler : /usr/bin/javac

Java headers gen.: /usr/bin/javah

Java archive tool: /usr/bin/jar

Non-system Java on macOS

trying to compile and link a JNI program

detected JNI cpp flags : -I$(JAVA_HOME)/../include -I$(JAVA_HOME)/../include/darwin

detected JNI linker flags : -L$(JAVA_HOME)/lib/server -ljvm

clang -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/../include -I/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/../include/darwin -I/usr/local/include -fPIC -Wall -g -O2 -c conftest.c -o conftest.o

clang -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress - L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o conftest.so conftest.o -L/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/server -ljvm -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation

JAVA_HOME /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre

Java library path: $(JAVA_HOME)/lib/server

JNI cpp flags : -I$(JAVA_HOME)/../include -I$(JAVA_HOME)/../include/darwin

JNI linker flags : -L$(JAVA_HOME)/lib/server -ljvm

Updating Java configuration in /Library/Frameworks/R.framework/Resources

Done.

Any help will be greatly appreciated!

解决方案

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值