Revert "don't use .gitignore for emacs files"
[filehash.git] / R / dump.R
blobfefae990ff3b065707efb5e7149d64c5d1d5c946
1 ######################################################################
2 ## Copyright (C) 2006, Roger D. Peng <rpeng@jhsph.edu>
3 ##     
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.
8 ## 
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.
13 ## 
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
17 ## 02110-1301, USA
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))
35     db
38 dumpDF <- function(data, dbName = NULL, type = NULL) {
39     if(is.null(dbName))
40         dbName <- as.character(substitute(data))
41     dumpList(as.list(data), dbName = dbName, type = type)
44 dumpList <- function(data, dbName = NULL, type = NULL) {
45     if(!is.list(data))
46         stop("'data' must be a list")
47     vnames <- names(data)
48     
49     if(is.null(vnames) || isTRUE("" %in% vnames))
50         stop("list must have non-empty names")
51     if(is.null(dbName))
52         dbName <- as.character(substitute(data))
53     
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]]])
60     db