knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "README-" )
withcon
is an R package that provides functionality
similar to the with
clause in Python;
It automatically closes connections after a series of operations and
also when an exception occurs during the operations.
Currently the functionality is provided for connection
objects
(created e.g. by file
and gzfile
) and
DBIConnection
objects (created by DBI::dbConnect
).
Install from GitHub using the devtools
library:
devtools::install_github('kota7/withcon')
library(withcon) library(DBI) res <- withCon(conn = dbConnect(RSQLite::SQLite(), ':memory:'), do = { dbWriteTable(conn, 'tbl', mtcars) dbReadTable(conn, 'tbl') }) head(res)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.