connect_local_database | R Documentation |
Create a local database in memory or on disk using
duckdb()
. This is the ideal method to experiment
on a small scale. DuckDB is a relational database similar to SQLite,
with full support for date and datetime data.
connect_local_database(file, timezone = Sys.timezone())
file |
A file path to an existing or new database file with a ".duckdb" extension. |
timezone |
A string for the time zone in which to return data to
R from the database. By default, it is set to |
This function creates a database on disk at the desired path. The database and its content will persist after it is disconnected.
A database connection object of class duckdb_connection
.
This method does not provide any encryption or password protection. You should only use this method with mock data unless you operate within a secure data enclave.
The duckdb
website provides excellent guidance on how to
connect to databases:
https://duckdb.org/docs/api/r
# Create database and load data
con <- connect_local_database("ramses-db.duckdb")
dplyr::copy_to(dest = con, df = reference_aware, name = "reference_aware",
overwrite = FALSE, temporary = FALSE)
# Close connection to database
DBI::dbDisconnect(con, shutdown=TRUE)
# Connect to the database again and show data
con <- connect_local_database("ramses-db.duckdb")
dplyr::tbl(con, "reference_aware")
DBI::dbDisconnect(con, shutdown=TRUE)
file.remove("ramses-db.duckdb")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.