Getting started

Connect to a Database This article is geared toward those who need to connect to an existing database using an ODBC driver. To review other options, such as using a database R package or JDBC, please refer to the Selecting a database interface page. If the intent is to learn with a local and small database, refer to the example in the dplyr page. Install the DBI and odbc package: install.packages("DBI") install.packages("odbc") Verify that odbc recognizes the installed drivers using odbcListDrivers().
Database Queries With R There are many ways to query data with R. This article shows you three of the most common ways: Using DBI Using dplyr syntax Using R Notebooks Background Several recent package improvements make it easier for you to use databases with R. The query examples below demonstrate some of the capabilities of these R packages. DBI. The DBI specification has gone through many recent improvements. When working with databases, you should always use packages that are DBI-compliant.
Overview dplyr as a database interface The dplyr package simplifies data transformation. It provides a consistent set of functions, called verbs, that can be used in succession and interchangeably to gain understanding of the data iteratively. dplyr is able to interact with databases directly by translating the dplyr verbs into SQL queries. This convenient feature allows you to ‘speak’ directly with the database from R. Other advantages of this approach are: