Installation of RODBC/ROracle packages on OS X Mavericks
Asked Answered
O

4

20

I have been trying to install some packages such as RODBC, ROracle or RGtk2 - used for rattle. I would really appreciate it if someone could help me get around this problem so that I could use these applications on a Mac with mavericks and with 3.1.1 R

I get this sort of error for both RODBC and RGtk2:

package ‘RGtk2’ is available as a source package but not as a binary Warning in install.packages : package ‘RGtk2’ is not available (for R version 3.1.1)

When I try to use type='source', I can download or start to download but then I get this sort of error message...

Warning in install.packages : installation of package ‘RODBC’ had non-zero exit status

Outage answered 6/10, 2014 at 5:11 Comment(1)
Note that the installation instructions for RGtk2 say that it requires the separate installation of the GTK libraries, and that this "can be a time consuming and apparently indirect process that involves installing numerous sub-libraries." So beware.Roee
R
31

This answer will cover installing RODBC and ROracle on OS X, specifically on Mavericks and later.

Both packages now need to be built (compiled) from source. This means that the first thing you need is to download XCode and the associated "command line tools" so that you actually have a compiler. How you do this has changed with basically every version of OS X/XCode, but if you start Googling you will probably end up landing here.

Once you have that in place...

RODBC

Since OS X 10.9 (Mavericks) Apple stopped including the iODBC SQL header files along with the "command line tools" that R users on OS X are accustomed to installing in order to build R packages from source.

So if you try to build RODBC from source on Mavericks at this point you should get an error like:

configure: error: "ODBC headers sql.h and sqlext.h not found"

To fix this, you need to download the latest version of iODBC (www.iodbc.org), and then unzip the file and set your header and library search paths to the location where you put the unzipped package. If you don't know how to set your search paths, you could just put the header files (sql.h and sqlext.h) in the /usr/include directory, and the libiodbc.a file in the /usr/lib directory.

Then you should be able to do

install.packages("RODBC",type = "source")

without any problems. Presumably this would work as well with the other major open source ODBC project, unixODBC, as well, but I have not tried that.

I have tested this (and the homebrew method in another answer) on El Capitan and both still work.

ROracle

This is more complicated. However, ROracle can be installed on OS X (I have tested this on Mountain Lion through El Capitan). Since ROracle relies on the Oracle Instant Client, there are no binaries available for any platform. There are detailed installation instructions for the package here.

For OS X, we need to (mostly) follow the Linux instructions.

First, download the appropriate Oracle Instant Client, as well as the SDK, as directed in the Linuz instructions.

The Linux install instructions mention installing the client from an RPM, which will place everything "in the right place". I wasn't able to figure out whether that even applied for OS X, so I simply unzipped the client in a directory I created and placed the SDK inside that directory in /sdk.

The Linux install instructions then direct us to create a symbolic link for libclntsh.so.11.1. Since this is OS X, it's actually called libclntsh.dylib.11.1. So we need to cd to the directory where we unzipped the client and then run

ln -s libclntsh.dylib.11.1 libclntsh.dylib

On OS X, we then set the DYLD_LIBRARY_PATH, not the LD_LIBRARY_PATH:

export DYLD_LIBRARY_PATH=/scratch/instantclient_11_2:$DYLD_LIBRARY_PATH

using whatever path is correct for your machine.

I was never able to get ROracle to compile with an OCI_LIB environment variable. Instead, I used the --with-oci-lib compiler flag option:

R CMD INSTALL --configure-args='--with-oci-lib=/scratch/instantclient_11_2' ROracle_1.1-11.tar.gz

again using whatever path and ROracle version number is appropriate.

If you are connecting to an Oracle database using a tnsnames.ora file, you'll also need to set a TNS_ADMIN environment variable to point to the location of that file.

One last gotcha: you may find (as I did) that this will all work only if you launch R from the command line (i.e. Terminal). Specifically, if you launch either RGui.app or RStudio.app from the GUI, and then try to run library(ROracle) you will get an error saying something to the effect of

> library("ROracle")
Error in dyn.load(file, DLLpath = DLLpath, ...) : 
  unable to load shared object '/Library/Frameworks/R.framework/Versions/3.1/Resources/library/ROracle/libs/ROracle.so':
  dlopen(/Library/Frameworks/R.framework/Versions/3.1/Resources/library/ROracle/libs/ROracle.so, 6): Library not loaded: /ade/b/3071542110/oracle/rdbms/lib/libclntsh.dylib.11.1
  Referenced from: /Library/Frameworks/R.framework/Versions/3.1/Resources/library/ROracle/libs/ROracle.so
  Reason: image not found
Error: package or namespace load failed for ‘ROracle’

This will happen even though Sys.getenv("DYLD_LIBRARY_PATH") faithfully reports the correct path.

For a while, I hacked together a "solution" where I created a shell script that launched RStudio/RGui upon startup, and just had to remember to always subsequently launch them via

open -a R.app
open -a RStudio.app

The problem apparently has to do with how environment variables are made available to GUI launched applications in OS X. As is usually the case, I eventually found the solution on StackOverflow. Editing the /etc/launchd.conf file solved this problem, so ROracle now loads even when RStudio/RGui are launched from the Finder. Though note here that the /etc/launchd.conf solution is no longer supported in Yosemite. That answer suggests you now need to set up a start-up plist file just to set the environment for launchctl on startup.

El Capitan Update for ROracle

I've now gone through the crucible on this one in El Capitan and it works as described above, but only if you disable System Integrity Protection first! Doing that is fairly quick, and instructions are easily found via Google.

Phew.

Roee answered 6/10, 2014 at 15:6 Comment(9)
I don't see the file "libiodbc.a" in the iODBC directory using "find . -name "libiodbc*" "Enchanting
@Enchanting I found all the download options for iODBC very confusing, it was in one of the things I downloaded, I can't remember which at the moment. The brew method below also works and might be easier...Roee
agreed! Very confusing. I finally went the brew route, which I found to be much easier. Really appreciate your help. Tgif!Enchanting
I'm Using ox 10 (Yosemite) and there is no such directory /usr/include. Should I create such? My PATH includes the next dirs: /usr/local/bin/:/usr/bin/:/bin;/usr/sbin/:/sbin/Ginny
@Ginny i think that installing the command line tools that come with Xcode should create the /usr/include tree, so if it's missing you may not have successfully done that. But frankly I prefer the brew method now for RODBC.Roee
Thanks, I had Xcode installed, but the the command line tools. (Installed from the command line: xcode-select --install. Then copied only the header files sql.h sqlext.h to /usr/include/ (had to sudo for that). And it worked. I didn't copied libiodbc.a as I couldn't find it.Ginny
Sorry to bring back the subject, but has anybody managed to make this solution work for OS X Sierra ? I don't want to start a question yet on SO if there is something that works already. The Error in dyn.load(file, DLLpath = DLLpath, ...) associated with ROracle.so appears every time you try to install the package regardless of the mean of installation (terminal or R), so far I've tried to adapt Linux answers but ROracle seems not to be in good terms with Mac OS X SierraLaunderette
Your answer was really helpful. Do you know if it's possible to include RODBC in a package via packrat or another method such that all recipients of the package won't need to do these steps?Rolfe
Disabling SIP immediately caused this to work on El Capitan, but is there any workaround that doesn't require restarting the whole computer and putting it in a less secure state?Omland
P
25

If you got homebrew,it would be easy. In terminal,use

brew install unixodbc

In r console,use

install.packages("RODBC",type="source")

Hope it will help

Planking answered 7/4, 2015 at 9:36 Comment(1)
Worked like a charm on El Captain. Easiest than the solution proposed by joranFreida
S
2

If you're using MacPorts, do this:

sudo port install unixODBC

Then, create (or, if it exists, edit) a file in your home directory

~/.R/Makevars

which should contain a line

CFLAGS += -I/opt/local/include

Then, you can install RODBC by

install.packages("RODBC",type="source")

Basically, the above

  • Installs the necessary libraries and header files
  • Tells R where to find them
  • Installs RODBC.
Straightlaced answered 25/5, 2015 at 18:42 Comment(0)
R
0

You will have to build the package from source by hand. If you go to the RODBC site, you'll notice that the binaries are not available for Mavericks. Download the package and follow the instruction for building a package from source. These are Windows instructions but the general idea is the same. You will need all the necessary OS packages which are being used during the build process of a particular package.

Rhumb answered 6/10, 2014 at 7:9 Comment(2)
'building by hand' ---does this mean that I have to replace my current install with the new install of R?Outage
@user3788557 building by hand means that you need (I'm giving you keywords to search for now) a build toolchain for your OS and compile the package from source. This is often done using R CMD build. I suggest you search for "creating r package" using your favorite search engine. Never mind, @Roee already answered...Shotputter

© 2022 - 2024 — McMap. All rights reserved.