Skip to content

Latest commit

 

History

History

r

Databases in R

You will need the RPostgres package in R for the materials here, as well as access to a PostgreSQL server. The examples here use the database from the PostgreSQL Tutorial.

RStudio version 1.1 and later has beta support for a database connections tab (by default a tab in the upper right). This tab is to let you manage your database connections and view the tables and views inside the database like we did with DataGrip. This functionality requires the installation of some special R packages and system packages. See ODBC requirements at https://github.com/r-dbi/odbc. Information on the Connections tab at https://support.rstudio.com/hc/en-us/articles/115010915687. Information on setting up odbc: https://cran.r-project.org/web/packages/odbc/readme/README.html#connection-strings. Note that you probably need to edit some system files -- at this point using this functionality requires fairly advanced knowledge of database connections and system files.

Files

If you haven't downloaded the entire repository, you can right-click the download links to save just those files. Be careful of the file type you save the file as.

R File shown in the workshop: download R Notebook | html

Exercises: html

Exercises with answers: download RMarkdown | html

Resources

RStudio Guide to Databases in R: covers different packages, connecting, writing queries, drivers, etc. Also has information about the Database Connections Pane in RStudio (in recent versions).

Overview of Databases in R: this uses SQLite, not PostgreSQL, as an example

Visualization and Databases in R: good discusion and examples of how to do visualizations of data that lives in a database without pulling it all into R first

Working with Databases in RStudio: features of RStudio, and packages created by RStudio, to help you work with databases in R; some of the features discussed are only available in development versions of RStudio at this point.

Databases Using R by Edgar Ruiz is an up-to-date overview

SQL Databases and R from Data Carpentry (part of a larger introductory R workshop)