Sep 29, 2019 This might be more of a general R environment problem, but I came across it while trying to load XLConnect after a clean reinstall, so I figured I'd try here. I was previously using XLConnect as part of a notebook successfully. Yesterday, however, I decided it was time to do a clean install of my mac for reasons that I won't go into. So I have a clean install of macOS, I installed R. Jun 05, 2018 @s-u, finally I have found the source of the problem.On Mac.onLoad only works fine if environment variable JAVAHOME and DYLDLIBRARYPATH are set, but they are not set on R GUI (even after sudo R CMD javareconf). When calling rJava via JRI, there was no problem with 0.9-9. However this commit (90897df) may have changed the behavior.Setting JAVAHOME and DYLDLIBRARYPATH.
The R script uses rJava and RJDBC packages to load tables from database. In Mac OS X, to correctly load this packages
requires the following steps borrowed from https://github.com/snowflakedb/dplyr-snowflakedb/wiki/Configuring-R-rJava-RJDBC-on-Mac-OS-X.
Steps have been modified to reflect problems (and it's solutions) reported here.
requires the following steps borrowed from https://github.com/snowflakedb/dplyr-snowflakedb/wiki/Configuring-R-rJava-RJDBC-on-Mac-OS-X.
Steps have been modified to reflect problems (and it's solutions) reported here.
Overview
This is the list of software downloads needed in order to connect R via
RJDBC
to a database:- Xcode Command Line Tools
- Java 6
- Java 8
- R
- rJava source package
- Database JDBC jar file
- RStudio (optional)
If you have any of this software already installed, you can skip that section.
Open Terminal.app
We'll change to the Downloads directory as we'll have to download some packages from the internet.
Rjava Image Not Found
Just to make debugging easier if something does not go as planned, log all output.
Xcode Command Line Tools
We need Xcode Command Line Tools, by running this command we will invoke the downloader if not installed, otherwise it will report it is already installed.
Java 6
Install the legacy Java 6 runtime which is needed despite us not going to use Java 6.
Now walk through the install to complete.
Java 8
Install Java 8. Note: newer versions may be available.
Now walk through the install to complete.
We'll run these two commands to output Java installations and what the current command defaults to. They are informative only.
You should see something like this:
R for OS X
Download and install the R package for OS X.
Now walk through the install to complete.
Now we need to tell R to use our Java 8 as it's
JAVA_HOME
You should see output similar to
Now install
rJava
from source and compile it against the Java 8 JDK.The 'unset JAVA_HOME' takes care of:Now let's check that rJava can be loaded correctly and returns the correct JDK version.This command should return the string
1.8.0_111-b14
(or whatever Java 8 version you installed).Finish
Exit from the script logging.
Using RStudio.app or R.app
A common error when trying to load rJava in RStudio is:
There are three ways to get around this problem and use
rJava
with RStudio or R console (R.app) :1 - Launching from the command line
You can launch it from the command line in Terminal.app like such:
![Rjava image not found Rjava image not found](/uploads/1/2/5/6/125663467/197129748.jpg)
![Rjava Rjava](/uploads/1/2/5/6/125663467/743211286.png)
This is a known limitation with RStudio on OS X. See this link for more details:[https://support.rstudio.com/hc/communities/public/questions/200650933-rJava-fails-to-load-in-RStudio-Desktop-OS-X](https://support.rstudio.com/hc/communities/public/questions/200650933-rJava-fails-to-load-in-RStudio-Desktop-OS-X)
2 - Make a symlink to libjvm.dylib
This is an alternate solution to loading RStudio, but must be updated any time you upgrade Java
+Based on this Stack Overflow thread, one can use the following to work around the
libjvm.dylib
loading issues.3 - Load the library in the script (which is the used approach in the CohortEx R script)
Just a bit of code in your R script: