0
0
R Programmingprogramming~5 mins

Database connections (DBI, RSQLite) in R Programming - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the DBI package in R?
DBI provides a common interface to connect and interact with databases in R, allowing you to send queries and retrieve data in a consistent way.
Click to reveal answer
beginner
How do you create a connection to an SQLite database using RSQLite?
Use dbConnect(RSQLite::SQLite(), dbname = "path_to_db.sqlite") to open a connection to an SQLite database file.
Click to reveal answer
beginner
What function do you use to run a SQL query and get results as a data frame in R?
Use dbGetQuery(connection, "SQL query") to send a query and get the results directly as a data frame.
Click to reveal answer
beginner
Why is it important to close a database connection in R?
Closing a connection with dbDisconnect(connection) frees resources and avoids locking the database, which helps keep your system stable.
Click to reveal answer
beginner
What does the function dbListTables() do?
It lists all the tables available in the connected database, helping you see what data you can access.
Click to reveal answer
Which function opens a connection to an SQLite database in R?
AdbOpen(RSQLite::SQLite(), "mydb.sqlite")
BconnectSQLite("mydb.sqlite")
CdbConnect(RSQLite::SQLite(), dbname = "mydb.sqlite")
DopenDB("mydb.sqlite")
How do you retrieve query results as a data frame in R?
AdbSendQuery(connection, "SELECT * FROM table")
BdbGetQuery(connection, "SELECT * FROM table")
CdbFetch(connection, "SELECT * FROM table")
DdbReadTable(connection, "table")
What is the purpose of dbDisconnect()?
ATo close the database connection
BTo open a new database connection
CTo list tables in the database
DTo execute a SQL query
Which package provides the interface to connect to databases in R?
ADBI
Bdplyr
Cggplot2
Dtidyr
What does dbListTables(connection) return?
AThe connection status
BThe number of rows in a table
CThe structure of a table
DA list of table names in the database
Explain how to connect to an SQLite database in R and retrieve data from a table.
Think about opening a door (connection) and then reading a book (query data).
You got /4 concepts.
    Describe why it is important to close a database connection after use in R.
    Imagine leaving a room open or closed after you finish using it.
    You got /4 concepts.