R rJava Error on Mac when loading xlsx library [duplicate] - r

This question already has answers here:
rJava load error in RStudio/R after "upgrading" to OSX Yosemite
(18 answers)
Closed 5 years ago.
when I execute the following code on Mac, I got this
**> library(xlsx)**
Loading required package: 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.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
Error: package ‘rJava’ could not be loaded
I saw some posts here that changes the directory of Java Home, but they are all in Windows system. I am wondering how can I fix this in a Mac environment?

Try this
If homebrew is not installed, install it from https://brew.sh/
Run this from terminal: brew cask install java
Reinstall rJava from R console
In general, and to avoid similar problems in the future, I suggest to follow my post to install R using homebrew http://pacha.hk/2017-07-12_r_and_python_via_homebrew.html
Doing that solves path problems and related stuff that can re-appear if later you want to use R database tools and related.

Related

I am facing issues while trying to install emojifont package on Mac book

I am installing emojifont package. The package installs properly however when I try to call it through the library function I get the following error
Error: package or namespace load failed for ‘emojifont’:
.onLoad failed in loadNamespace() for 'sysfonts', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/Library/Frameworks/R.framework/Versions/3.6/Resources/library/sysfonts/libs/sysfonts.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.6/Resources/library/sysfonts/libs/sysfonts.so, 6): Library not loaded: /opt/X11/lib/libfreetype.6.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/3.6/Resources/library/sysfonts/libs/sysfonts.so
Reason: image not found
What ended up working for me was installing XQuartz. I had this problem with both emojifont and sysfonts until I installed XQuartz and then both loaded without problems. I can't tell you much about what XQuartz is doing but it seems to be needed for the compatibility between MacOS and these packages.
Other people with this problem seemed to be having issues with their sysfonts install (like it needed to be updated, etc.) but that didn't work for me, instead I got an error when using trying to load both the sysfonts and the emojifont package. If you look at this line in the error "Library not loaded: /opt/X11/lib/libfreetype.6.dylib", that seems to be missing in the error message of people with only the sysfonts problem.
Hope this saves someone the 2 hours I just spent searching!

RWeka installation under Rstudio on Mac

I tried to find solutions from previous posts, but they do not solve my problem.
I am using macOS High Sierra and have Java installed. Below is the error reported by Rstudio. Also, rJava, Mac, and R are really messy with each other. I found this post but still does not work.
https://github.com/MTFA/CohortEx/wiki/Run-rJava-with-RStudio-under-OSX-10.10,-10.11-(El-Capitan)-or-10.12-(Sierra)
///////////////////
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.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
In addition: Warning message:
package ‘RWeka’ was built under R version 3.4.4
I met the same question and I found this is helpful.
Cannot load R xlsx package on Mac OS 10.11
1.In terminal enter the following to relink Java correctly:
sudo R CMD javareconf
2.Back in R (or RStudio) install the rJava package from source:
install.packages("rJava",type='source')
Then
library(rJava)
and
library(RWeka)
should work.

Installed rJava, Installed Java 8 update. Still cannot load rJava on MacOS Sierra

Bear in mind that I am computer illiterate and new to R. I have installed the rJava package in R studio version 1.0.143 and installed Java 8 (using MacOS Sierra). When I try to load the rJava package:
library(rJava)
I get the following error
Unable to find any JVMs matching version "(null)".
No Java runtime present, try --request to install.
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
'/Users/cormac/Library/R/3.4/library/rJava/libs/rJava.so':
dlopen(/Users/cormac/Library/R/3.4/library/rJava/libs/rJava.so, 6):
Library not loaded: #rpath/libjvm.dylib
Referenced from:
/Users/cormac/Library/R/3.4/library/rJava/libs/rJava.so
Reason: image not found
In addition: Warning messages:
1: package ‘rJava’ was built under R version 3.4.2
2: running command '/usr/libexec/java_home' had status 1
Could somebody help me to interpret this error message? There is probably a very simple solution, but I am completely lost. Thank you!!
As noted in Unable to load rJava in RStudio, there is a very specific sequence of steps that must be taken to get rJava to work on a Macbook, as documented in rJava Issues #86.
Download and install Java from Oracle
Uninstall any previously installed version of rJava
Add JAVA_HOME to your .bashrc
Close & restart terminal, R and RStudio sessions so they pick up the updated JAVA_HOME
Use install.packages() to install rJava
See the URL link above for additional details on each step.

Error installing packages in R after messing with "pahts"

I was trying to install the rattle package in R and got this error message saying
configure: error: GTK version 2.8.0 required
ERROR: configuration failed for package ‘RGtk2’
Then I tried to fix the RGtk2 problem using this guide
http://marcoghislanzoni.com/blog/2014/08/29/solved-installing-rattle-r-3-1-mac-os-x-10-9/
I tried this code in the Mac OS terminal (but this is above my understanding) :
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
sudo port selfupdate
sudo port install pkgconfig
export PATH=/opt/pkgconfig/bin:$PATH
sudo port install gtk2 +x11
export PKG_CONFIG_PATH=/opt/local/lib/pkgconfig
It gave me this answer
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
ad-mac0630:~ caruc35$ sudo port selfupdate
Password:
Sorry, try again.
Password:
And locked down.
I also installed XCode command line tools from Apple and tried some stuff from the guide above. It didnt get the rattle package to work so I erased it.
After messing with this the rattle package does still not work and R seems not to work as it did before. For example i can´t load the xlsx package getting this error message:
Loading required package: 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 '/Users/caruc35/Library/R/3.4/library/rJava/libs/rJava.so':
dlopen(/Users/caruc35/Library/R/3.4/library/rJava/libs/rJava.so, 6): Library not loaded: #rpath/libjvm.dylib
Referenced from: /Users/caruc35/Library/R/3.4/library/rJava/libs/rJava.so
Reason: image not found
Error: package ‘rJava’ could not be loaded
Did I mess up when trying to change PATH? Is there a way to reset everything back to normal?
I have tried reinstalling R but the same problems still occurs.

TclTk library issue while install Rcmdr package on MacBookPro [duplicate]

This question already has answers here:
Error ".onLoad failed in loadNamespace() for 'tcltk'"
(7 answers)
Closed 7 years ago.
I get the following ERROR while trying to load Rcmdr for R on my MacBook Pro:
> library("Rcmdr")
Error : .onLoad failed in loadNamespace() for 'tcltk', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/Library/Frameworks/R.framework/Versions/3.0/Resources/library/tcltk/libs/tcltk.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.0/Resources/library/tcltk/libs/tcltk.so, 10): Library not loaded: /usr/local/lib/libtcl8.6.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/3.0/Resources/library/tcltk/libs/tcltk.so
Reason: image not found
Error: package or namespace load failed for ‘Rcmdr’
I have other problem on this machine related to the TclTk libraries, but I didn't get any help when I posted about troubles installing graphviz.
If someone could help me fix the TclTk library issue I would really appreciate it.
Thanks in advance.
Thank your #donal-fellows !
The solutions was to put symlinks to the libs where R expected them:
brew remove tcl-tk
brew -v install tcl-tk --with-tk
ln -s /usr/local/Cellar/tcl-tk/8.6.0/lib/libtcl8.6.dylib /usr/local/lib/libtcl8.6.dylib
ln -s /usr/local/Cellar/tcl-tk/8.6.0/lib/libtk8.6.dylib /usr/local/lib/libtk8.6.dylib
let us now hope that this fixes my graphviz issue!

Resources