Description Usage Arguments Details Implementation Author(s) See Also Examples
The function clear removes the tables associated with a collection of dbframe objects from their data bases.
1 |
... |
Each argument listed should be a dbframe object. |
The table is removed and not just emptied, so the column names and types are discarded as well.
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 |
Gray Calhoun gcalhoun@iastate.edu
dbRemoveTable
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.