h4sci / h4sci-tasks

Tasks and Exercises
7 stars 0 forks source link

Block 2, Task 4: A Little SQL #8

Open mbannert opened 3 years ago

mbannert commented 3 years ago

Set up and connect to an sqlite database using R.

Here's some basic syntax

library(RSQLite)
# row names are not stored in the DB
# that's why we add an extra column here
mtcars$name <- row.names(mtcars)

db_path = "data/h4sci.sqlite3"
con <- dbConnect(RSQLite::SQLite(), db_path)
dbWriteTable(con, dbQuoteIdentifier(con,"mtcars"), mtcars)
# Only do this when you're done playing
dbDisconnect(con)

Add your favorite dataset from the fivethirtyeight package to that database.

Evaluate the following statement critically:

"If your data fits in memory there is no advantage to putting it in a database: it will only be slower and more frustrating." -- taken from the {dbplyr} documentation

Note: The teaching server has the RSQLite package installed and tested.