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

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.

Related

How to install the rgl package in macOS Big Sur

I have been trying to install the rgl package in my macOS Big Sur, but I have failed each time.
I have downloaded R from the CRAN website, and have also installed Xquartz. After rebooting the computer, I tried to install the rgl package from the R console. It installs successfully, but whenever I type library("rgl") in the R console, the package does not load, and instead, this is shown :
Error in dyn.load(dynlib <- getDynlib(dir)) :
unable to load shared object '/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/rgl/libs/rgl.so':
dlopen(/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/rgl/libs/rgl.so, 6): Symbol not found: _hb_buffer_add_utf8
Referenced from: /Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/rgl/libs/rgl.so
Expected in: flat namespace
in /Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/rgl/libs/rgl.so
Error: package or namespace load failed for ‘rgl’:
.onLoad failed in loadNamespace() for 'rgl', details:
call: rgl.init(initValue, onlyNULL)
error: OpenGL is not available in this build
In addition: Warning messages:
1: Loading rgl's DLL failed.
This build of rgl depends on XQuartz, which failed to load.
See the discussion in https://stackoverflow.com/a/66127391/2554330
2: Trying without OpenGL...
I headed to the link that this error message mentions, and tried uninstalling rgl and Xquartz, and reinstalling them again, but the issue remains.
Moreover, here it is said that I am supposed to delete org.xquartz.startx.plist from /Library/LaunchDaemons, but from the terminal, after navigating to the Library directory, it seems that there is nothing named LaunchDaemons or LaunchAgents.
Any help would be appreciated. I am using macOS Big Sur 11.4, Xquartz 2.8.1 and rgl 0.106.8. Thanks.

rJava installation fails on macOS 10.14

After upgrading to MacOS Mojave (10.14.1), I'm no longer able to install rJava for R version 3.5.1 with Java version "1.8.0_102" installed.
I tried the previous solution for MacOS 10.11 but it still did not work, giving this 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.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
Posting the solution I found in case it helps others -- I don't quite understand why this work or if it's the right way so looking for better alternatives!
This issue lead to this Apple forum where it's stated
For legacy software that looks for the macOS headers in the base system under /usr/include, please install the package file located at: /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14. pkg
To do this, open terminal and run these commands
cd /Library/Developer/CommandLineTools/Packages/
open macOS_SDK_headers_for_macOS_10.14.pkg
then follow prompts to install the package.
After this, in the terminal, configure rJava and install as in the previous answer
sudo R CMD javareconf
R -e "install.packages('rJava')"
and it should install without problem.
After installing JDK 11.04 LTS I rain into the same error in R Studio on Mojave
R was expecting Library not loaded: /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk
Despite running sudo R CMD javareconf the error still persisted
Therefore I browsed to /Library/Java/JavaVirtualMachines/ in finder and renamed the folder "jdk-11.0.4.jdk" to "jdk-11.0.1.jdk"
Restarted R and both library(rJava) and library(xlsx) now work.
Hope this helps someone
I ran into the exact problem. I solved it by:
Install the latest version of Java (dmg file)
Install rJava in Studio: install.packages("rJava")
In the terminal: sudo mv jdk-12.0.1.jdk jdk-11.0.1.jdk
Otherwise the following error will appear in Rstudio:
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-11.0.1.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
In Rstudio: library(rJava)
rJava should have been loaded without issues.
I ran into same issue, when i was trying to install "rJava" in my macOs (Mojave version).
Below steps i executed to resolve issue.
R version : 3.6.1
issue : configure: error: one or more Java tools are missing.
*** JDK is incomplete! Please make sure you have a complete JDK. JRE is not sufficient.
solution : execute below command in your terminal
$ /usr/libexec/java_home -V
Matching Java Virtual Machines (1):
1.8.0_162, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk(your Java version)/Contents/Home
$ export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home
$ export PATH=$JAVA_HOME/bin:$PATH
$ R CMD javareconf
$ R --quiet -e 'install.packages("rJava", type="source", repos="http://cran.us.r-project.org")'

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.

Incompatible library version RSiena

I'm trying to load the RSiena package into R, but keep getting this error message:
Error: package or namespace load failed for ‘RSiena’:
.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.4/Resources/library/tcltk/libs/tcltk.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.4/Resources/library/tcltk/libs/tcltk.so, 10): Library not loaded: /opt/X11/lib/libfontconfig.1.dylib
Referenced from: /usr/local/lib/libtk8.6.dylib
Reason: Incompatible library version: libtk8.6.dylib requires version 11.0.0 or later, but libfontconfig.1.dylib provides version 10.0.0
I tried installing three ways:
install.packages("RSiena") , install.packages("RSiena", repos="http://R-Forge.R-project.org") , and installing straight from tgz file (from https://cran.r-project.org/web/packages/RSiena/index.html).
The first two installation methods do not give any error and say The downloaded binary packages are in /var/folders/mk/__r_sbzn5mx88x04mrlycsg00000gq/T//RtmpbxlMY8/downloaded_packages.The third option gives this message Error in install.packages : type == "both" cannot be used with 'repos = NULL'
None allow me to load the package. I'm working with R version 3.4.3 (2017-11-30) in RStudio Version 1.1.423 on Mac OS X El Capitan (version 10.11.6).
I've tried uninstalling and reinstalling. I'm not sure how else to troubleshoot this issue.
The most recent version (RSiena v.1.2.26) of rsiena addresses tcltk issues, and is now available on Github here: https://github.com/snlab-nl/rsiena.
SOLUTION. I installed XQuartz from xquartz.macosforge.org and now the package loads successfully.

Error: package ‘rJava’ could not be loaded when installing xlsx

Im trying to install the xlsx package. Installing works fine but when i load the library I get the following error:
> require(xlsx)
Loading required package: xlsx
Loading required package: rJava
Error : .onLoad failed in loadNamespace() for 'rJava', details:
call: fun(libname, pkgname)
error: No CurrentVersion entry in Software/JavaSoft registry! Try re- installing Java and make sure R and Java have matching architectures.
In addition: Warning messages:
1: package ‘xlsx’ was built under R version 3.2.3
2: package ‘rJava’ was built under R version 3.2.3
Failed with error: ‘package ‘rJava’ could not be loaded’
I googled around and say that installing the right version of Java might be the issue. However, when I downloaded the newest version and started a new r-session I still get the same issue.
Are there more people experiencing this issue? And some quick fix?
I am using Linux and when I update R or Java to use the rJava library (needed by xlsx) I need to run this commands form a shell (outside the R session)
sudo su -
R CMD javareconf
I hope this helps.

Resources