Is it possible to read the data stored in MS SQL server from R interface?
If it is I would be also thankful if anyone could show the way to do it.
The latest library that allows you to connect to MSSQL databases is RSQLServer.
It can be found on GitHub and CRAN.
Niko, What operating system are you running? The answer to your question varies, depending on the platform you are using.
If you are using Windows (of any stripe), connecting to MSSQL Server via ODBC (RODBC) makes the most sense. When I connect to a MSSQL Server on Linux, I use JDBC as suggested by Joris. I would assume that JDBC is also the best solution for Macs, but I could very well be wrong.
Tried the RODBC
package already?
http://cran.r-project.org/web/packages/RODBC/index.html
There's also the RJDBC
package : http://www.rforge.net/RJDBC/
See also : http://www.r-bloggers.com/connecting-to-sql-server-from-r-using-rjdbc/
There another option that seems to outperform RODBC and RJDBC
rsqlserver package written by agstudy.
Installation:
require(devtools)
install_github("rClr", 'jmp75')
install_github('rsqlserver', 'agstudy',args='--no-multiarch')
library("RODBC")
dbhandle <- odbcDriverConnect('driver={SQL Server};server=;database=;trusted_connection=true')
currTableSQL<-paste("SELECT * FROM ",sep="")
currTableDF<-sqlQuery(dbhandle,currTableSQL)
You can connect to SQL server using DBI package, which I think works better than RODBC. DBI is a database interface package for relational databases. for SQL I use it along with odbc package as in the example below.
Visit this page for full details: Database Queries with R
An example would be as follows
library(DBI)
library(odbc)
con <- dbConnect(odbc::odbc(), .connection_string = "driver={SQL Server}; server= ServerName; database=DatabaseName; trusted_conncetion=true"))
dbGetQuery(con,'Select * from Table')