0

I have just updated my R-Studio to version 3.3.3. to 3.4.3 in OSX I am trying to open an excel file using package xlsx, and have also re-installed rjava, but on executing the library(rJava) it gives me the following error:

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': 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

I have tried few fixes described here (rJava load error in RStudio/R after "upgrading" to OSX Yosemite) but it doesn't work for me. How can I resolve this issue?

  • did you run `R CMD javareconf`? – David Gohel Feb 28 '18 at 14:03
  • @DavidGohel Yes, I did, but I still get the following error. (Sorry, I didn't mention that I use a Mac OS. (*** JAVA_HOME is not a valid path, ignoring Java interpreter : /usr/bin/java Java version : 1.6.0_65 Java home path : /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home Java compiler : /usr/bin/javac Java headers gen.: /usr/bin/javah Java archive tool: /usr/bin/jar Non-system Java on macOS) – Shruti Gupta Feb 28 '18 at 14:14
  • And were all your R sessions closed? – David Gohel Feb 28 '18 at 14:16
  • @DavidGohel yup they were closed. I am a newbie in using R. I tried uninstalling and reinstalling the rjava as well, but it doesn't seem to work. – Shruti Gupta Feb 28 '18 at 14:17
  • ok. (FYI, rJava can difficult to install). I don't think you need `JAVA_HOME`. I never needed it ;) What is your java version? – David Gohel Feb 28 '18 at 14:21
  • @DavidGohel my java version is : rJava_0.9-9 – Shruti Gupta Feb 28 '18 at 14:23
  • no, java version? in a terminal, run `java --version` – David Gohel Feb 28 '18 at 14:24
  • @DavidGohel sorry, its java version "1.6.0_65" – Shruti Gupta Feb 28 '18 at 14:27
  • Could you remove JAVA_HOME and then run (all R sessions closed) R CMD javareconf and show the output? (edit your question as it's difficult to read in comments) – David Gohel Feb 28 '18 at 14:29
  • @DavidGohel How shall I remove JAVA_HOME? When I run -R CMD javareconf it gives the same error. – Shruti Gupta Feb 28 '18 at 15:40
  • Yes, the error is telling you that JAVA_HOME is wrong: "JAVA_HOME is not a valid path". You have a env variable named JAVA_HOME that does not point to a valid path, remove it (unset) – David Gohel Feb 28 '18 at 15:47
  • @DavidGohel I unset the path as suggested. (wrote the following to my bash file: export JAVA_HOME=$(/usr/libexec/java_home -v 1.6.0_65)/jre export LD_LIBRARY_PATH=$JAVA_HOME/jre/lib/server unset DYLD_LIBRARY_PATH. It still doesn't work. – Shruti Gupta Feb 28 '18 at 16:02
  • I mean unset all env variables you could have set and let R CMD javareconf do the work. See https://cran.r-project.org/doc/manuals/r-release/R-admin.html#Java-support – David Gohel Feb 28 '18 at 16:11
  • @DavidGohel I have unset the JAVA_HOME variable (I could only found this env variable) and run R CMD javareconf. Now, it does not show me that JAVE_HOME is an invalid path but gives me another error (missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun Unable to compile a JNI program) and (Updating Java configuration in /Library/Frameworks/R.framework/Resources Done.) I tried to run rJava again in R studio, and it gives the same error as I mentioned in my question. – Shruti Gupta Feb 28 '18 at 16:39
  • Oh sorry, you said you wrote export instructions in your bash file... OK, so now you need to install xcode with command `xcode-select --install` – David Gohel Feb 28 '18 at 16:49
  • @DavidGohel Sorry for the confusion I may have created David. I have now installed the xcode. :-) – Shruti Gupta Feb 28 '18 at 17:02
  • @DavidGohel Sorry for the confusion I may have created David. I have now installed the xcode. :-) – Shruti Gupta Feb 28 '18 at 17:02
  • @DavidGohel now when I run R CMD javareconf, it gives me the following error: conftest.c:1:10: fatal error: 'jni.h' file not found #include ^~~~~~~ 1 error generated. make: *** [conftest.o] Error 1 Unable to compile a JNI program – Shruti Gupta Feb 28 '18 at 17:28
  • if you are still trying, reinstall java, then run R CMD javareconf (or sudo ...) and then you should be able to install rJava. If not working, I can not do more... On my mac os X, I just installed java, then ran R CMD javareconf and it worked. I think most people are messing their config by trying to add env PATH, linked, etc... :) – David Gohel Mar 01 '18 at 08:53
  • @DavidGohel thanks for your time David. I am still trying to fix this problem. I will post the solution here, hopefully, i'll get one :-) – Shruti Gupta Mar 01 '18 at 09:51
  • I uninstalled and reinstalled Java again, the rJava works now :-) – Shruti Gupta Mar 01 '18 at 15:46
  • cool. I will try to make a note of this later. – David Gohel Mar 01 '18 at 15:50

0 Answers0