|
Loading Data from a SQL / Access Database
Directly connecting to a SQL or Access database can save the user the hassle of downloading the data, saving the data in a CSV format, and loading the CSV into R. Instructions for linking to a SQL / Access database is provided in the following sections. Loading Database via the RODBC package
The RODBC package provides the easiest method for linking to a database. Linking to a database using the RODBC package can be accomplished per the following steps.
library(RODBC) channel = odbcConnect("DSN_Name", uid = "UserID", pwd="Password") Data = sqlFetch(channel,"DataTableName") EXAMPLE: > library(RODBC) > channel = odbcConnect("MyData", uid = "User1", pwd="Password1") > Data = sqlFetch(channel,"ExperimentData") Setting up a System DSN
A System Data Source Name (DSN) allows for direct database access on your local machine. A number of online resources exist to help you set up a System DSN and can be found via a quick web search. A few resources are provided below to get you started. Setting up a SQL Server System DSN Setting up a Access System DSN |