Closed walinchus closed 5 years ago
Try restarting R and run install.packages("rJava")
and then library("rJava")
.
Yes I've tried this a few times with no luck. This is me trying this again just now:
Restarting R session...
install.packages("rJava") trying URL 'https://cran.rstudio.com/bin/macosx/el-capitan/contrib/3.6/rJava_0.9-11.tgz' Content type 'application/x-gzip' length 745354 bytes (727 KB)
downloaded 727 KB
The downloaded binary packages are in /var/folders/y9/l7s4rm2x0g934jww243w_mxh0000gn/T//Rtmph9ElST/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.6/Resources/library/rJava/libs/rJava.so': dlopen(/Library/Frameworks/R.framework/Versions/3.6/Resources/library/rJava/libs/rJava.so, 6): Library not loaded: /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home/lib/server/libjvm.dylib Referenced from: /Library/Frameworks/R.framework/Versions/3.6/Resources/library/rJava/libs/rJava.so Reason: image not found
I deleted all the other javas I had, and downloaded Java 11. The only Java 11 available for download (that I could find anywhere) was Java 11.0.2. It looks like the R package keeps trying to find Java version 11.0.1 or maybe I'm reading that wrong. I usually never use Java honestly but it's a dependency for a package I need.
It shouldn't matter though as I have set the Java home to the current folder and it is still putting up an error:
options("java.home"="/Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk/Contents/Home/lib")
options("java.home") $java.home [1] "/Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk/Contents/Home/lib"
Restarting R session...
install.packages("rJava") trying URL 'https://cran.rstudio.com/bin/macosx/el-capitan/contrib/3.6/rJava_0.9-11.tgz' Content type 'application/x-gzip' length 745354 bytes (727 KB)
downloaded 727 KB
The downloaded binary packages are in /var/folders/y9/l7s4rm2x0g934jww243w_mxh0000gn/T//RtmpS6a84E/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.6/Resources/library/rJava/libs/rJava.so': dlopen(/Library/Frameworks/R.framework/Versions/3.6/Resources/library/rJava/libs/rJava.so, 6): Library not loaded: /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home/lib/server/libjvm.dylib Referenced from: /Library/Frameworks/R.framework/Versions/3.6/Resources/library/rJava/libs/rJava.so Reason: image not found
And thank you for helping on this.
Did you run R CMD javareconf
to configure your R with the Java you installed? (see R documentation)
So this is interesting. I mean it's crazy but helpful to know.
I thought, this package is clearly looking for a folder that says "jdk-11.0.1.jdk" no matter what I do, what if I just... changed the folder name? So I changed "openjdk-11.0.2.jdk" to "jdk-11.0.1.jdk". And the R package loaded! I thought myself so clever. Then I tried to load the xlsx package. And a giant bomb picture appeared on my screen. And my R session had a fatal error. And yeah that was dumb. But anyway I think it's a bug with rJava.
It's not, JDKs are compatible. If you see a "giant bomb" provide details - what software are you using? R doesn't show any bombs. If you're using RStudio (it's not R!) then file a report with them. If the issue exists with R then file here.
Oh thank you Jesus. Ok so I had run the R CMD javareconf several times:
But this past time it did something different and asked me to overwrite stuff. I said yes:
Daddy-Mac-418:~ Lucia$ R CMD javareconf Java interpreter : /Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk/Contents/Home/bin/java Java version : 11.0.2 Java home path : /Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk/Contents/Home Java compiler : /Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk/Contents/Home/bin/javac Java headers gen.: /usr/bin/javah Java archive tool: /Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk/Contents/Home/bin/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 clang -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk/Contents/Home/include/darwin -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -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/openjdk-11.0.2.jdk/Contents/Home/lib/server -ljvm -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
JAVA_HOME : /Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk/Contents/Home 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 override rw-r--r-- root/admin for /Library/Frameworks/R.framework/Resources/etc/Makeconf? (y/n [n]) y override rw-r--r-- root/admin for /Library/Frameworks/R.framework/Resources/etc/ldpaths? (y/n [n]) y Done.
Daddy-Mac-418:~ Lucia$
Then everything else would finally load:
library(rJava) library(xlsx) install.packages("ImportExport") trying URL 'https://cran.rstudio.com/bin/macosx/el-capitan/contrib/3.6/ImportExport_1.1.tgz' Content type 'application/x-gzip' length 139374 bytes (136 KB)
downloaded 136 KB
The downloaded binary packages are in /var/folders/y9/l7s4rm2x0g934jww243w_mxh0000gn/T//RtmpCWLHvv/downloaded_packages
library(ImportExport) Loading required package: gdata gdata: read.xls support for 'XLS' (Excel 97-2004) files ENABLED.
gdata: read.xls support for 'XLSX' (Excel 2007+) files ENABLED.
Attaching package: ‘gdata’
The following object is masked from ‘package:stats’:
nobs
The following object is masked from ‘package:utils’:
object.size
The following object is masked from ‘package:base’:
startsWith
Loading required package: Hmisc Loading required package: lattice Loading required package: survival Loading required package: Formula Loading required package: ggplot2
Attaching package: ‘Hmisc’
The following objects are masked from ‘package:base’:
format.pval, units
Loading required package: chron Loading required package: RODBC
Thank you so so much Simon for your help. Sorry I had thought this was an underlying R issue which is why I had filed it here.
Sorry I meant to comment and close.
Please help. I have done like 20 things and none work. rJava will not load. Which I need for xlsx. Which I need for ImportExport. Which I need to run an mdb file in R.
I tried installling new versions of Java, I tried setting the directory of rJava to my current path, I tried restarting R, the whole shebang. Nothing works. Please help.
This is what I did in R:
And this is what I did simultaneously pretty much in my terminal window: