Classes "remoteDB" and "localDB"

Share:

Description

These functions create an interface for a simple file-based key-value database using remote storage via http

Objects from the "remoteDB" and "localDB" classes

Objects can be created by calls of the form new("remoteDB", ...) and new("localDB", ...) respectively.

Slots

url:

Object of class "character", url of the remote database

dir:

Object of class "character", local directory in which to download the data or local directory in which to create a database

Methods

dbDelete

signature(db = "remoteDB", key = "character"): Calling dbDelete on a remoteDB object returns an error.

dbDelete

signature(db = "localDB", key = "character"): Calling dbDelete on a localDB deletes the specified key from the database and updates the repository version.

dbExists

signature(db = "remoteDB", key = "character"): For each element in the vector key, dbExists returns TRUE if the key is in the database and otherwise returns FALSE.

dbExists

signature(db = "localDB", key = "character"): For each element in the vector key, dbExists returns TRUE if the key is in the database and otherwise returns FALSE.

dbFetch

signature(db = "remoteDB", key = "character"): Checks if the provided character value key exists in the local directory. If not, dbFetch downloads the data files for the current version. Otherwise, dbFetch reads the file from the local directory. The function returns the data object associated with the key.

dbFetch

signature(db = "localDB", key = "character"): Checks if the provided character value key exists in the local directory. If the key exists in the local directory, then dbFetch reads the file from the local directory. The function returns the data object associated with the key.

dbInsert

signature(db = "remoteDB", key = "character", value = "ANY"): Calling dbInsert on a remoteDB object returns an error.

dbInsert

signature(db = "localDB", key = "character", value = "ANY"): Calling dbInsert on a localDB object writes the value to a file corresponding to the specified key in the local directory and updates the version of the repository.

dbList

signature(db = "remoteDB"): The method dbList returns a character vector of all the keys in the database.

dbList

signature(db = "localDB"): The method dbList returns a character vector of all the keys in the database.

dbSync

signature(db = "remoteDB", key = "character"): If key = NULL, Updates all key/data pairs in the local directory to the most recent repository version on the remote server. If key is a character vector, then it only updates the specified key/data pairs (in which case, it first checks to ensure that all specified keys' files have been previously saved).

dbCreate

signature(db = "remoteDB"): Calling dbCreate on a remoteDB object creates the local main directory and data sub-directory for storing the data files and saves the url associated with the remoteDB object in the R workspace format in the local main directory. dbCreate is called implicitly when new is called to create the remoteDB object so calling dbCreate explicitly is usually not necessary.

dbCreate

signature(db = "localDB"): Calling dbCreate on a localDB object creates the local main directory and data sub-directory to in which to store the data files. dbCreate is called implicitly when new is called to create the localDB object so calling dbCreate explicitly is usually not necessary.

Author(s)

Sandy Eckel, Roger D. Peng

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
## Not run: 
## Objects of the class localDB

wd <- getwd()
dir <- file.path(wd,"localDBExample")

## Create local stashR data repository 'localDBExample'
fhLocal <- new("localDB", dir = dir, name = "localDBExample")

## Insert key-value data into 'localDBExample' 
v <- 1:10
dbInsert(fhLocal,key = "vector", value = v)
m <- matrix(1:20,5,4)
dbInsert(fhLocal,key = "matrix", value = m)
d <- data.frame(cbind(id = 1:5, age=c(12,11,15,11,14), sex = c(1,1,0,1,0)))
dbInsert(fhLocal,key = "dataframe", value = d)
l <- list(v = v, m = m, df = d)
dbInsert(fhLocal, key = "list", value = l)

dbList(fhLocal)

dbFetch(fhLocal, "dataframe") 
dbDelete(fhLocal, "vector")
dbExists(fhLocal, "vector")
dbList(fhLocal) 


## Objects of the class remoteDB

## The same key-value data used in the previous example for localDB
## has been stored in a remoteDB repository on the internet at:
myurl <- "http://www.biostat.jhsph.edu/~seckel/remoteDBExample"

wd <- getwd()
dir <- file.path(wd,"remoteDBExample") 
## Create local copy of data repository 'remoteDBExample'
fhRemote <- new("remoteDB", url= myurl, 
            dir = dir, name= "remoteDBExample")

dbList(fhRemote)
dbExists(fhRemote,c("vector", "array","list", "function"))
## downloads 'vector' data from the remoteDB repository
dbFetch(fhRemote, "vector") 
## fetches without downloading again 
dbFetch(fhRemote, "vector") 
## synchronize all local copies of the data to the remote version
dbSync(fhRemote, key = NULL)

## End(Not run)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.