1 ######################################################################
2 ## Copyright (C) 2006, Roger D. Peng <rpeng@jhsph.edu>
4 ## This program is free software; you can redistribute it and/or modify
5 ## it under the terms of the GNU General Public License as published by
6 ## the Free Software Foundation; either version 2 of the License, or
7 ## (at your option) any later version.
9 ## This program is distributed in the hope that it will be useful,
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ## GNU General Public License for more details.
14 ## You should have received a copy of the GNU General Public License
15 ## along with this program; if not, write to the Free Software
16 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 #####################################################################
20 dumpImage <- function(dbName = "Rworkspace", type = NULL) {
21 dumpObjects(list = ls(envir = globalenv(), all.names = TRUE),
22 dbName = dbName, envir = globalenv())
25 dumpObjects <- function(..., list = character(0), dbName, type = NULL,
26 envir = parent.frame()) {
27 names <- as.character(substitute(list(...)))[-1]
28 list <- c(list, names)
29 if(!dbCreate(dbName, type))
30 stop("could not create database file")
31 db <- dbInit(dbName, type)
33 for(i in seq(along = list))
34 dbInsert(db, list[i], get(list[i], envir))
38 dumpDF <- function(data, dbName = NULL, type = NULL) {
40 dbName <- as.character(substitute(data))
41 dumpList(as.list(data), dbName = dbName, type = type)
44 dumpList <- function(data, dbName = NULL, type = NULL) {
46 stop("'data' must be a list")
49 if(is.null(vnames) || isTRUE("" %in% vnames))
50 stop("list must have non-empty names")
52 dbName <- as.character(substitute(data))
54 if(!dbCreate(dbName, type))
55 stop("could not create database file")
56 db <- dbInit(dbName, type)
58 for(i in seq(along = vnames))
59 dbInsert(db, vnames[i], data[[vnames[i]]])