Trouble loading/installing rJava on Mac

4,358 views
Skip to first unread message

Toby Maxwell

unread,
May 4, 2017, 4:50:51 PM5/4/17
to davi...@googlegroups.com
Hi all, it seems to be a common problem, but I can't get rJava to install or load properly, I have updated all of my R and Rstudio software, running mac OS 10.12.4, Sierra.

I used to be able to run it, but the problem started after updating R. Now when trying to load rJava I get the following errors. Not sure if anyone has any pointers, I included some of my 'steps' i.e. failures below.

Thanks!!

Toby

-Trying to load the package:

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

-A number of online help forums suggest that I need to reinstall java and tell rjava where to find it, which I did and didn't get much out of it.

done by opening R Studio via the terminal:
LD_LIBRARY_PATH=$(/usr/libexec/java_home)/jre/lib/server: open -a RStudio

-I noticed as I tried reinstalling rJava that the rJava install comes up with the following error:

clang: error: unsupported option '-fopenmp'
make[2]: *** [libjri.jnilib] Error 1
make[1]: *** [src/JRI.jar] Error 2
make: *** [jri] Error 2
ERROR: compilation failed for package ‘rJava’
* removing ‘/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava’
Warning in install.packages :
  installation of package ‘rJava’ had non-zero exit status


--
Toby Maxwell

Ph.D. Candidate
Plant and Environmental Sciences Building, 3242
Department of Land, Air, and Water Resources
Agricultural and Environmental Chemistry Graduate Group

Alex Mandel

unread,
May 4, 2017, 5:02:34 PM5/4/17
to davi...@googlegroups.com
The error in the package install indicates that the Clang compiler isn't
working. Online others have reported that using the C++ compiler from
gcc (possibly installed via homebrew) might work better.

Poking around online led to
https://gist.github.com/hrbrmstr/6f228eead691e72bd0272a25319ea9ee which
answers
http://stackoverflow.com/questions/43632512/cannot-install-rjava-from-source-as-c-compiler-works-no?noredirect=1#comment74322210_43632512

I did also see a suggestion that installing OpenMP might solve the Clang
error, but that wasn't rJava specific.

Note for Mac/Linux users, whenever you update Java do a R CMD javareconf
before updating R packages that require Java.

Enjoy,
Alex Mandel, PhD

Center for Spatial Sciences
http://spatial.ucdavis.edu
Geospatial and Farming Systems Research Consortium
http://gfc.ucdavis.edu
University of California, Davis

Spencer Mathews

unread,
May 4, 2017, 5:46:04 PM5/4/17
to davi...@googlegroups.com
It's now possible to install R (and RStudio) through Anaconda. Managing your R packages using Conda should ease dependency management and circumvent these frustrating build issues.

No promises, but this could be an easy solution (rJava is available through the conda R channel).


Good luck,
Spencer

--
Check out our R resources at http://d-rug.github.io/
--- You received this message because you are subscribed to the Google Groups "Davis R Users' Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to davis-rug+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/davis-rug.
For more options, visit https://groups.google.com/d/optout.

Toby Maxwell

unread,
May 4, 2017, 7:19:51 PM5/4/17
to davi...@googlegroups.com
Worked on the various forum based options with no luck.

Installed via anaconda then it was happy.

Thanks y'all.

Toby

Matt Espe

unread,
May 8, 2017, 2:25:44 PM5/8/17
to Davis R Users' Group
In my experience, most issues with R and Java can be solved with:

R CMD javareconf

At the terminal, then re-installing rJava. Might be worth a try next time before switching to a different distribution system. Anaconda is both convenient and another thing to troubleshoot when something does not work. 

Matt
To unsubscribe from this group and stop receiving emails from it, send an email to davis-rug+...@googlegroups.com.

--
Check out our R resources at http://d-rug.github.io/
---
You received this message because you are subscribed to the Google Groups "Davis R Users' Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to davis-rug+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages