clear: Remove a table from the database

Description Usage Arguments Details Implementation Author(s) See Also Examples

Description

The function clear removes the tables associated with a collection of dbframe objects from their data bases.

Usage

1

Arguments

...

Each argument listed should be a dbframe object.

Details

The table is removed and not just emptied, so the column names and types are discarded as well.

Implementation

The first step is to define a generic clear function. The actual function is a method for the dbframe class. Methods for other classes could be defined as well.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
<<*>>=
    setGeneric("clear", function(...)
               standardGeneric("clear"), signature = "...")

    setMethod("clear", signature = "dbframe", function(...) {
      x <- list(...)
      sapply(x, function(y) {
        stopifnot(!readonly(y))
        dbc <- dbConnect(y)
        results <- <<Remove table referenced by "y" from database>>
        dbDisconnect(dbc)
        results
      })})

Removing the table is pretty easy since we can just use methods defined by DBI.

1
2
3
4
5
6
7
<<Remove table referenced by "y" from database>>=
res <- 
  if (is.linked(y)) {
    dbRemoveTable(dbc, tablename(y),...)
  } else {
    FALSE
  }

Author(s)

Gray Calhoun gcalhoun@iastate.edu

See Also

dbRemoveTable

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
filename <- tempfile(fileext = ".db")
example.dbframe <- dbframe("clear1", dbname = filename)
example2.dbframe <- dbframe("clear2", dbname = filename)
clear(example.dbframe, example2.dbframe)

data(chickwts)
insert(example.dbframe) <- chickwts
head(example.dbframe)
clear(example.dbframe)
head(example.dbframe)
unlink(filename)

grayclhn/dbframe-R-library documentation built on May 17, 2019, 8:33 a.m.