SQL Server 2016 – How to Install RODBC Driver for R Services

r-servicessql-server-2016

I'm trying to get started with R services on SQL Server 2016. I was following this example from MS on youtube.

2 min 22sec into the vid John shows a reference to library(RODBC)… which I don't have. So I have downloaded the RODBC driver from CRAN

According to the documentation:

RODBC is simple to install, and binary distributions are available for
Windows from CRAN

But it provides no further details about how to install it. It mentions an ODBC Driver Manager but not much more than that.

So.. How do I install RODBC?

Do I unzip it to a specific path?
Is there a utility or tool required to install it?
Do I run a script?

Best Answer

To install R packages in SQLServer 2016, you first have to launch R GUI (somewhere like D:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\R_SERVICES\bin\x64\Rgui.exe).

If your server is connected to the web, you can launch a :

install.packages("RODBC")

Otherwise, download the package (see https://cran.r-project.org/web/packages/RODBC/index.html), put it your server, for instance in a folder D:\R_Packages, and launch the R command :

setwd("D:/R_Packages")
install.packages("RODBC_1.3-14.zip", repos=NULL)

This second method is not very convenient in case of package dependencies : you'll have to download / install manually all the packages needed....

Anyway, in you want RODBC to access SQLServer databases, maybe you don't need it. Have a look at sp_execute_external_script procedure which help you to connect directly R and SQLServer.