0
0
R Programmingprogramming~10 mins

Database connections (DBI, RSQLite) in R Programming - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to load the DBI package.

R Programming
library([1])
Drag options to blanks, or click blank then click option'
ADBI
BRSQLite
Cdplyr
Dggplot2
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to load RSQLite instead of DBI first.
2fill in blank
medium

Complete the code to connect to an in-memory SQLite database.

R Programming
con <- DBI::dbConnect([1], ":memory:")
Drag options to blanks, or click blank then click option'
ARSQLite::SQLite()
BSQLite
CRSQLite
DDBI
Attempts:
3 left
💡 Hint
Common Mistakes
Passing just 'RSQLite' or 'SQLite' without calling the function.
3fill in blank
hard

Fix the error in the code to disconnect from the database.

R Programming
DBI::dbDisconnect([1])
Drag options to blanks, or click blank then click option'
Aconnection
Bconn
Cdb
Dcon
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that was not defined for the connection.
4fill in blank
hard

Fill both blanks to create a table named 'people' with columns 'name' and 'age'.

R Programming
DBI::dbExecute(con, "CREATE TABLE [1] ([2] TEXT, age INTEGER)")
Drag options to blanks, or click blank then click option'
Apeople
Bperson
Cname
Dfullname
Attempts:
3 left
💡 Hint
Common Mistakes
Using singular table name or wrong column name.
5fill in blank
hard

Fill all three blanks to insert a person named 'Alice' aged 30 into the 'people' table.

R Programming
DBI::dbExecute(con, "INSERT INTO people ([1], age) VALUES ('[2]', [3])")
Drag options to blanks, or click blank then click option'
Aname
BAlice
C30
Dage
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing column names or values, or forgetting quotes around the name.