Tuesday, December 13, 2011

Accessing SQL Server DB from R on Linux using RODBC package

First of all you'll need to install FreeTDS package.

brew update
brew install unixodbc
brew install freetds
It looks like there is no need to specify --with-unixodbc any more.


I would add only that I had to edit not
/etc/odbcinst.ini
but
/usr/local/etc/odbcinst.ini,

On Linux it looks like this
[FreeTDS]
Description = TDS driver (Sybase/MS SQL)
Driver = /usr/lib/odbc/libtdsodbc.so
Setup = /usr/lib/odbc/libtdsS.so
Threading = 1
CPTimeout =
CPReuse = 
FileUsage = 1

On Mac paths are a bit different
[FreeTDS]
Description = TDS driver (Sybase/MS SQL)
Driver = /usr/local/lib/libtdsodbc.so
Setup = /usr/local/lib/libtdsS.so
Threading = 1
CPTimeout =
CPReuse = 
FileUsage = 1


then it worked just fine.
Here is a sample code:
library(RODBC)
# replace server.name, database.name, user.id, password and T_my_table correspondingly
con <- odbcDriverConnect("DRIVER={FreeTDS};SERVER=server.name;DATABASE=database.name;UID=user.id;PWD=password;")
strSql <- "select * from T_my_table"
x <- sqlQuery(con, strSql)
close(con)
cat(x)

Checking font availability on Mac   fc-list : family | grep "Fira Code"   or   system_profiler -json SPFontsDataType | grep \...