After a fairly extensive search, I noticed that a number of people are having a hard time finding a start-to-finish guide that answers this question. (At least one question notes that a solution exists, but the proposed solution does not get around the fact that, by default, RODBC attempts to compile against iODBC, which is not included with Yosemite.) I just went through this process, so I thought I would document it here in the hope that it will benefit others. I am connecting to a SQL Server database.
-
Thanks, hrbrmstr. Excellent advice. I just made the change from my iPhone, but I'll double-check it when I get on my laptop again. Thanks! – Justin O Barber Aug 09 '15 at 18:15
-
Can you include in your question some of the errors/issues others have encountered? That will increase the probability they'll find this question if they search. – Joshua Ulrich Aug 09 '15 at 19:13
-
Not sure if you heard, there is [rsqlserver](https://github.com/agstudy/rsqlserver) package which is different from [RSQLServer](https://github.com/imanuelcostigan/RSQLServer) shared on CRAN. The first one offers more native driver to sql server, should provide better speed than ODBC or JDBC. Not sure if it works on Mac. – jangorecki Aug 09 '15 at 20:06
-
Thanks, Joshua. I will do this as soon as I am able to get back on my laptop. Great idea. – Justin O Barber Aug 09 '15 at 21:45
-
Thanks, Jangorecki. I checked out the second option you mentioned but not the first. I will give it a look as soon as I have the chance. – Justin O Barber Aug 09 '15 at 21:46
-
1Related: [Installing ODBC via HomeBrew](https://apple.stackexchange.com/q/199658/22781). – kenorb Oct 24 '17 at 15:18
1 Answers
Using Homebrew as my OS X package manager, I can install RODBC
with the following steps (assuming I have already installed R).
Install
unixodbc
:$ brew install unixodbc
Install
freetds
(replacing/usr/local/Cellar/unixodbc/2.3.2_1
with yourunixodbc
directory, if necessary):$ brew install --with-tdsver=8.0 --with-msdblib --with-unixodbc=/usr/local/Cellar/unixodbc/2.3.2_1 freetds
Configure your
freetds
installation (the following is a minimal configuration file):freetds.conf
# server specific section [global] ; tds version = 8.0 ; dump file = /tmp/freetds.log ; debug flags = 0xffff ; timeout = 10 ; connect timeout = 10 text size = 64512 [TESTSQL] # insert the actual host below host = <xxx.xx.x.xx> port = 1433 tds version = 8.0
Test the
freetds
config:$ tsql -H `<xxx.xx.x.xx>` -p 1433 -U `<username>` -P `<password>`
locale is "en_US.UTF-8" locale charset is "UTF-8" using default charset "UTF-8" 1> exit
Configure your
unixodbc
installation (the following is a minimal configuration file):$ sudo vim /usr/local/Cellar/unixodbc/2.3.2_1/etc/odbcinst.ini
odbcinst.ini
[MSSQL] Description = Microsoft SQL Server driver Driver = /usr/local/Cellar/freetds/0.95.18/lib/libtdsodbc.so
(and another minimal installation file):
$ sudo vim /usr/local/Cellar/unixodbc/2.3.2_1/etc/odbc.ini
odbc.ini
[ODBC Data Sources] TESTSQL = Test database [TESTSQL] Driver = MSSQL Servername = TESTSQL Port = 1433 Database = TMSEPRD TDS_Version = 8.0
Test the new configuration with
isql
:$ isql TESTSQL `<username>` `<password>`
+---------------------------------------+ | Connected! | | | | sql-statement | | help [tablename] | | quit | | | +---------------------------------------+ SQL> quit
Create a symbolic link to the files in your home directory:
$ ln -vs /usr/local/Cellar/freetds/0.95.18/etc/freetds.conf ~/.freetds.conf $ ln -vs /usr/local/Cellar/unixodbc/2.3.2_1/etc/odbc.ini ~/.odbc.ini $ ln -vs /usr/local/Cellar/unixodbc/2.3.2_1/etc/odbcinst.ini ~/.odbcinst.ini
Find and modify your
RProfile
file by appending the following line(s) of code to the file (replacing/usr/local/include
with the include directory that contains yoursql.h
andsqlext.h
files; the second line may be unnecessary if the directory does not exist):$ vim /Library/Frameworks/R.framework/Versions/3.2/Resources/library/base/R/Rprofile Sys.setenv(ODBC_INCLUDE="/usr/local/include") Sys.setenv(ODBC_LIBS="/usr/local/lib")
Now download the
RODBC
package source (which you an download here) to your Downloads folder.Open a new R console session and install the package (replacing
RODBC_1.3-12.tar.gz
with the name of your package source):install.packages("~/Downloads/RODBC_1.3-12.tar.gz", repos=NULL, type="source")
The package should now work:
> library(RODBC)
> myconn <- odbcConnect("TESTSQL", uid="<userid>", pwd="<password>")
Thanks to Jared Folkins and Gabi Huiber for help with figuring out what directories R looks in by default for the requisite files for RODBC.

- 155,785
- 88
- 678
- 743

- 11,291
- 2
- 40
- 45
-
1see, macs are easy! thanks for this...spent way too much time wrestling with this. – SqlACID Jan 11 '17 at 17:46
-
I used steps 1-6 to get package odbc working with a MSSQL database. Note that the [servername] in freetds.conf has to be different from the [differentservername] in odbc.ini ! – Jack Wasey Apr 24 '18 at 22:46