knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "README-"
)

Travis-CI Build Status AppVeyor Build Status

withcon

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).

Installation

Install from GitHub using the devtools library:

devtools::install_github('kota7/withcon')

Example

library(withcon)
library(DBI)
res <- withCon(conn = dbConnect(RSQLite::SQLite(), ':memory:'), do = {
  dbWriteTable(conn, 'tbl', mtcars)
  dbReadTable(conn, 'tbl')
})
head(res)


kota7/withcon documentation built on May 29, 2019, 6:53 p.m.