Open and close DBI connections

Share:

Description

A database-backed survey design object contains a connection to a database. This connection will be broken if the object is saved and reloaded, and the connection should ideally be closed with close before quitting R (although it doesn't matter for SQLite connections). The connection can be reopened with open.

Usage

1
2
3
4
5
6
7
8
## S3 method for class 'DBIsvydesign'
open(con, ...)
## S3 method for class 'DBIsvydesign'
close(con, ...)
## S3 method for class 'ODBCsvydesign'
open(con, ...)
## S3 method for class 'ODBCsvydesign'
close(con, ...)

Arguments

con

Object of class DBIsvydesign or ODBCsvydesign

...

Other options, to be passed to dbConnect or dbDisconnect, or odbcReConnect or odbcDisconnect

Value

The same survey design object with the connection opened or closed.

See Also

svydesign

DBI package

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
## Not run: 
library(RSQLite)
dbclus1<-svydesign(id=~dnum, weights=~pw, fpc=~fpc,
data="apiclus1",dbtype="SQLite",
dbname=system.file("api.db",package="survey"))

dbclus1
close(dbclus1)
dbclus1
try(svymean(~api00, dbclus1))

dbclus1<-open(dbclus1)
open(dbclus1)
svymean(~api00, dbclus1)

## End(Not run)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.