with_db_connection | R Documentation |
Connections to Database Management Systems which automatically disconnect. In
particular connections which are created with DBI::dbConnect()
and closed
with DBI::dbDisconnect()
.
with_db_connection(con, code)
local_db_connection(con, .local_envir = parent.frame())
con |
For |
code |
|
.local_envir |
|
[any]
The results of the evaluation of the code
argument.
withr
for examples
db <- tempfile()
with_db_connection(
list(con = DBI::dbConnect(RSQLite::SQLite(), db)), {
DBI::dbWriteTable(con, "mtcars", mtcars)
})
head_db_table <- function(...) {
con <- local_db_connection(DBI::dbConnect(RSQLite::SQLite(), db))
head(DBI::dbReadTable(con, "mtcars"), ...)
}
head_db_table()
unlink(db)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.