Errors loading rJava - ".onLoad failed in loadNamespace() for 'rJava', details..."

rjava
rweka
xlsx

#1

I have trouble running "library(xlsx)". Every time I run it, I get an error( See the attachment). I already downloaded package readxl and xlsx and java, but it still cannot work. How to set the Java environment variable in R?

BTW, my computer system is Mac OS. Could you help me with this, please?


Issue with installed Rweka package
RWeka installation
Issue with installed Rweka package
#2

Does this work for you in R, but not in RStudio? (see FAQ below for disambiguation)

If you're on a Mac, this guide can be helpful for getting rJava running right:


#3

Thank you! Could you tell me how to find the path of Java8 on my computer? I'm stuck here


#4

Hi there,

I have been receiving error messages about a installed package Rweka.

library(Rweka)
Error: package or namespace load failed for ‘RWeka’:
.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.5/Resources/library/rJava/libs/rJava.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.5/Resources/library/rJava/libs/rJava.so, 6): Library not loaded: /Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home/lib/server/libjvm.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/3.5/Resources/library/rJava/libs/rJava.so
Reason: image not found

The background of the OS is macOS High Sierra, RStudio Version 1.1.456, R version 3.5.1. With the previous error I have installed the rJava package and the JRE version 10.0.2.
Additionally, I have also ran this code

sudo R CMD javareconf

as suggested here.

I would greatly appreciate for any suggestions that will resolve this issue.
Thank you,
Bradley


#5

Does this work for you in R, but not in RStudio? (see FAQ below for disambiguation)

If you're on a Mac, this guide can be helpful for getting rJava running right:


#6

Hi @dataandme,

I have tried to install and run rJava in R. But I am seeing the same errors.

install.packages("rJava")
--- Please select a CRAN mirror for use in this session ---
trying URL 'https://mirrors.sorengard.com/cran/bin/macosx/el-capitan/contrib/3.5/rJava_0.9-10.tgz'
Content type 'application/octet-stream' length 735656 bytes (718 KB)
==================================================
downloaded 718 KB
The downloaded binary packages are in
/var/folders/k7/5mqy2vtj3d76plpc758dthvm0000gn/T//RtmpOdW3Ys/downloaded_packages

library(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.5/Resources/library/rJava/libs/rJava.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.5/Resources/library/rJava/libs/rJava.so, 6): Library not loaded: /Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home/lib/server/libjvm.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/3.5/Resources/library/rJava/libs/rJava.so
Reason: image not found

Additionally the Installing rJava on macOS does not work.

Thanks


#7

Well, you're definitely not the only one who struggles with the rJava installation (I wish I had more careful notes form when I finally got my installation to work)—it's a commonly problematic install.

This thread seems to be struggling with the same issue:

We've hit the limit of my rJava skills. @xujingsi, if you don't mind (and you as well @bradvision) could we combine this threads, and rename with something about rJava (since that seems to be the root problem). That way, hopefully we'll be able to get more-expert eyes on it.


#9

Do any of the suggestions here work for you?


#10

There are a few other possibilities for getting rJava installed correctly in this StackOverflow thread, as well:

More extensive instructions available here:


#11

Thank you, Mara. I found the path, but I encountered another problem. Something went wrong when I set Java 8 gloablly.


#12

I'm not sure what's going on there. Hopefully someone else will know. In the future, fi you could paste the text of the error messages, it's easier to read than screenshots, and it will make searching for them easier as well!


#13

Hi everyone,

I have been able to access Zhiya Zho's rJava installation guide. I am very thankful of the guide that he put together. But I am still coming up in errors in terminal when I am running part 5 R CMD javareconf in terminal. I am unable to bypass this in order to install rJava. As per Zhiya's suggestion in the comments under the installation guide I have installed the Xcode Command Line Tools. Yet, I am running into errors at R CMD javareconf. I would appreciate if anyone else could provide some other solution.

MacBook-Pro:.R username $ R CMD javareconf
Java interpreter : /Users/username/.jenv/shims/java
Java version : 1.8.0_181
Java home path : /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/jre
Java compiler : /Users/username/.jenv/shims/javac
Java headers gen.: /Users/username/.jenv/shims/javah
Java archive tool: /Users/username/.jenv/shims/jar

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
/usr/local/Cellar/gcc/7.2.0/bin/gcc-7 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/jre/../include -I/Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/jre/../include/darwin -I/usr/local/include -fPIC -Wall -g -O2 -c conftest.c -o conftest.o
/bin/sh: /usr/local/Cellar/gcc/7.2.0/bin/gcc-7: No such file or directory
make: *** [conftest.o] Error 127
Unable to compile a JNI program

JAVA_HOME : /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/jre
Java library path:
JNI cpp flags :
JNI linker flags :
Updating Java configuration in /Library/Frameworks/R.framework/Resources
Done.

MacBook-Pro:.R username$


#14

Thank you, Mara. It's a good suggestion. I didn't notice before.
I will paste the text here and hope someone else will help me.

I encountered a problem when I am running the last code of part 3 jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home oracle64-1.8.0_162 added

I already found the path on my computer,

wireless-10-105-238-245:~ jingsixu$ ls -l `which java`
lrwxr-xr-x  1 root  wheel  74 Mar 28 05:53 /usr/bin/java -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java

However, this path didn't work.

wireless-10-105-238-245:~ jingsixu$ jenv add /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java is not a valid path to java installation
wireless-10-105-238-245:~ jingsixu$ oracle64-1.8.0_162 added
-bash: oracle64-1.8.0_162: command not found
wireless-10-105-238-245:~ jingsixu$ jenv add /Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java is not a valid path to java installation
wireless-10-105-238-245:~ jingsixu$ oracle64-1.8.0_162 added

#16

Hi, Bradvison. I finally figured out what's wrong on this step.
you may need to check out do you have this folder? "/usr/local/Cellar/gcc/7.2.0/bin/gcc-7"
The way to check out: Finder-->Go-->Go to folder

For me, it is " /usr/local/Cellar/gcc/8.2.0/bin/gcc-8"

And you might need to edit on the step4 and check out if you save it successfully.


#17

Hi everyone,
I successfully followed all the things written in Zhiya Zuo's rJava installation guide
but I encountered another error when I tested

> library(xlsx)
Error: package or namespace load failed for ‘xlsx’ in get(Info[i, 1], envir = env):
 lazy-load database '/Library/Frameworks/R.framework/Versions/3.5/Resources
/library/rJava/R/rJava.rdb' is corrupt
In addition: Warning message:
In get(Info[i, 1], envir = env) : internal error -3 in R_decompress1

I don't know what this means.
Hope someone can help me. Thanks

Jingsi


#18

I reopened the R studio and rerun the code. no error happen again. So Happy!


#19

Hi, xujingsi

Pardon me for not responding within the day. So I too followed the Zhiya Zuo's installation guide and it appears that I have successfully installed rJava. Yet, I am unable for the RWeka package to work. Hence, I am unsure whether the rJava installation was successful. I will looking into your suggestions and get back to you.

Thank you,
Bradley