From 1658a087fbb14dee9358359d8578e15f1943068a Mon Sep 17 00:00:00 2001 From: "Roger D. Peng [audrey]" Date: Mon, 17 Mar 2008 09:56:00 -0400 Subject: [PATCH] Tabs --> Spaces --- R/filehash-RDS.R | 122 +++++++++++++++++++++++++++---------------------------- 1 file changed, 61 insertions(+), 61 deletions(-) diff --git a/R/filehash-RDS.R b/R/filehash-RDS.R index fbfbd3f..5c58af4 100644 --- a/R/filehash-RDS.R +++ b/R/filehash-RDS.R @@ -27,29 +27,29 @@ setClass("filehashRDS", setValidity("filehashRDS", function(object) { - if(length(object@dir) != 1) - return("only one directory should be set in 'dir'") - if(!file.exists(object@dir)) - return(gettextf("directory '%s' does not exist", - object@dir)) - TRUE + if(length(object@dir) != 1) + return("only one directory should be set in 'dir'") + if(!file.exists(object@dir)) + return(gettextf("directory '%s' does not exist", + object@dir)) + TRUE }) createRDS <- function(dbName) { - dir <- dbName - - if(!file.exists(dir)) - dir.create(dir) - else - message(gettextf("database '%s' already exists", dbName)) - TRUE + dir <- dbName + + if(!file.exists(dir)) + dir.create(dir) + else + message(gettextf("database '%s' already exists", dbName)) + TRUE } initializeRDS <- function(dbName) { - ## Trailing '/' causes a problem in Windows? - dbName <- sub("/$", "", dbName, perl = TRUE) - new("filehashRDS", dir = normalizePath(dbName), - name = basename(dbName)) + ## Trailing '/' causes a problem in Windows? + dbName <- sub("/$", "", dbName, perl = TRUE) + new("filehashRDS", dir = normalizePath(dbName), + name = basename(dbName)) } ## For case-insensitive file systems, objects with the same name but @@ -58,18 +58,18 @@ initializeRDS <- function(dbName) { ## reverses the operation. mangleName <- function(oname) { - gsub("([A-Z])", "@\\1", oname, perl = TRUE) + gsub("([A-Z])", "@\\1", oname, perl = TRUE) } unMangleName <- function(mname) { - gsub("@", "", mname, fixed = TRUE) + gsub("@", "", mname, fixed = TRUE) } ## Function for mapping a key to a path on the filesystem setGeneric("objectFile", function(db, key) standardGeneric("objectFile")) setMethod("objectFile", signature(db = "filehashRDS", key = "character"), function(db, key) { - file.path(db@dir, mangleName(key)) + file.path(db@dir, mangleName(key)) }) ################################################################################ @@ -78,68 +78,68 @@ setMethod("objectFile", signature(db = "filehashRDS", key = "character"), setMethod("dbInsert", signature(db = "filehashRDS", key = "character", value = "ANY"), function(db, key, value, ...) { - ## open connection to a gzip compressed file - con <- gzfile(objectFile(db, key), "wb") - - ## serialize data to connection; return TRUE on success - tryCatch({ - serialize(value, con) - }, error = function(err) { - err - }, interrupt = function(cond) { - cond - }, finally = close(con)) + ## open connection to a gzip compressed file + con <- gzfile(objectFile(db, key), "wb") + + ## serialize data to connection; return TRUE on success + tryCatch({ + serialize(value, con) + }, error = function(err) { + err + }, interrupt = function(cond) { + cond + }, finally = close(con)) } ) setMethod("dbFetch", signature(db = "filehashRDS", key = "character"), function(db, key, ...) { - ## create filename from key - ofile <- objectFile(db, key) - - con <- tryCatch({ - gzfile(ofile, "rb") - }, error = function(cond) { - cond - }) - if(inherits(con, "condition")) - stop(gettextf("error obtaining value for key '%s': %s", - key, - conditionMessage(con))) - on.exit(close(con)) - - val <- unserialize(con) - val + ## create filename from key + ofile <- objectFile(db, key) + + con <- tryCatch({ + gzfile(ofile, "rb") + }, error = function(cond) { + cond + }) + if(inherits(con, "condition")) + stop(gettextf("error obtaining value for key '%s': %s", + key, + conditionMessage(con))) + on.exit(close(con)) + + val <- unserialize(con) + val }) setMethod("dbExists", signature(db = "filehashRDS", key = "character"), function(db, key, ...) { - key %in% dbList(db) + key %in% dbList(db) }) setMethod("dbList", "filehashRDS", function(db, ...) { - ## list all keys/files in the database - fileList <- dir(db@dir, all.files = TRUE, full.names = TRUE) - use <- !file.info(fileList)$isdir - fileList <- basename(fileList[use]) + ## list all keys/files in the database + fileList <- dir(db@dir, all.files = TRUE, full.names = TRUE) + use <- !file.info(fileList)$isdir + fileList <- basename(fileList[use]) - unMangleName(fileList) + unMangleName(fileList) }) setMethod("dbDelete", signature(db = "filehashRDS", key = "character"), function(db, key, ...) { - ofile <- objectFile(db, key) - - ## remove/delete the file - status <- file.remove(ofile) - isTRUE(status) + ofile <- objectFile(db, key) + + ## remove/delete the file + status <- file.remove(ofile) + isTRUE(status) }) setMethod("dbUnlink", "filehashRDS", function(db, ...) { - ## delete the entire database directory - d <- db@dir - unlink(d, recursive = TRUE) + ## delete the entire database directory + d <- db@dir + unlink(d, recursive = TRUE) }) -- 2.11.4.GIT