Description Objects from the "remoteDB" and "localDB" classes Slots Methods Author(s) Examples
These functions create an interface for a simple file-based key-value database using remote storage via http
Objects can be created by calls of the form
new("remoteDB", ...)
and new("localDB", ...)
respectively.
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
signature(db = "remoteDB", key = "character")
:
Calling dbDelete
on a remoteDB
object returns an
error.
signature(db = "localDB", key = "character")
:
Calling dbDelete
on a localDB
deletes the specified
key from the database and updates the repository version.
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.
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.
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
.
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
.
signature(db = "remoteDB", key =
"character", value = "ANY")
: Calling dbInsert
on a remoteDB
object returns an error.
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.
signature(db = "remoteDB")
:
The method dbList
returns a character vector of all the
keys in the database.
signature(db = "localDB")
:
The method dbList
returns a character vector of all the
keys in the database.
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).
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.
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.
Sandy Eckel, Roger D. Peng
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.