Package Filehash': R Topics Documented
Package Filehash': R Topics Documented
R topics documented:
createQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
createS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
dbInit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
dbLoad . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
dumpObjects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
filehash-class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
filehashFormats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
filehashOption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
queue-class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
stack-class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
stackqueue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1
2 createS
Index 13
Description
Create or initialize a queue data structure using filehash databases
Usage
createQ(filename)
initQ(filename)
Arguments
filename character, file name for storing the queue data structure
Details
A new queue can be created using createQ, which creates a file for storing the queue information
and returns an object of class "queue".
Value
The createQ and initQ functions both return an object of class "queue".
Author(s)
Roger D. Peng <[email protected]>
Description
Create or initialize a stack data structure using filehash databases
Usage
createS(filename)
initS(filename)
Arguments
filename character, file name for storing the stack data structure
dbInit 3
Details
A new stack can be created using createS, which creates a file for storing the stack information
and returns an object of class "stack".
Value
The createS and initS functions both return an object of class "stack".
Author(s)
Roger D. Peng <[email protected]>
Description
Interface for creating and initializing a simple file-based hash table
Usage
dbCreate(db, ...)
dbInit(db, ...)
dbReconnect(db, ...)
Arguments
db name of database or a database object
type type of database format. If missing, the default type will be used
... other arguments passed to methods
Details
dbCreate creates the necessary files or directory for the database. If those files already exist nothing
is done.
dbInit takes a database name and returns an object inheriting from class "filehash".
The type argument specifies the format in which the database should be stored on the disk. If not
specified, the default type will be used (as specified by filehashOption).
4 dbLoad
Value
dbCreate returns TRUE upon success and FALSE in the event of an error. dbInit returns an object
inheriting from class "filehash"
Note
Author(s)
Roger D. Peng
See Also
See filehash-class more information and examples and filehashOption for setting the default
database type.
Description
Usage
db2env(db)
dbLoad(db, ...)
dbLazyLoad(db, ...)
Arguments
db database object
env an environment
keys character vector of database keys to load
... other arguments passed to methods
dbLoad 5
Details
db2env loads the entire database db into an environment via calls to makeActiveBinding. There-
fore, the data themselves are not stored in the environment, but a function pointing to the data in
the database is stored. When an element of the environment is accessed, the function is called to
retrieve the data from the database. If the data in the database is changed, the changes will be
reflected in the environment.
dbLoad loads objects in the database directly into the environment specified, like load does except
with active bindings. dbLoad takes a second argument env, which is an environment, and the default
for env is parent.frame().
The use of makeActiveBinding in db2env and dbLoad allows for potentially large databases to, at
least conceptually, be used in R, as long as you don’t need simultaneous access to all of the elements
in the database.
With dbLazyLoad database objects are "lazy-loaded" into the environment. Promises to load the
objects are created in the environment specified by env. Upon first access, those objects are copied
into the environment and will from then on reside in memory. Changes to the database will not
be reflected in the object residing in the environment after first access. Conversely, changes to the
object in the environment will not be reflected in the database. This type of loading is useful for
read-only databases.
Value
For db2env, an environment is returned, the elements of which are the keys of the database. For
dbLoad and dbLazyLoad, a character vector is returned (invisibly) containing the keys associated
with the values loaded into the environment.
Author(s)
Roger D. Peng
See Also
dbInit and filehash-class
Examples
dbCreate("myDB")
db <- dbInit("myDB")
dbInsert(db, "a", rnorm(100))
dbInsert(db, "b", 1:10)
as(db, "list")
Description
Dump R objects to a filehash database
Usage
dumpObjects(..., list = character(0), dbName, type = NULL, envir = parent.frame())
dumpImage(dbName = "Rworkspace", type = NULL)
dumpDF(data, dbName = NULL, type = NULL)
dumpList(data, dbName = NULL, type = NULL)
dumpEnv(env, dbName)
Arguments
... R objects to dump
list character vector of names of objects to dump
dbName character, name of database to which objects should be dumped
type type of database to create
envir environment from which to obtain objects
data a data frame or a list
env an environment
Details
Objects dumped to a database can later be loaded via dbLoad or can be accessed with dbFetch,
dbList, etc. Alternatively, the with method can be used to evaluate code in the context of a
database. If a database with name dbName already exists, objects will be inserted into the exist-
ing database (and values for already-existing keys will be overwritten).
dumpDF is different in that each variable in the data frame is stored as a separate object in the
database. So each variable can be read from the database separately rather than having to load the
entire data frame into memory. dumpList works in a simlar way.
The dumpEnv function takes an environment and stores each element of the environment in a
filehash database.
filehash-class 7
Value
Author(s)
Roger D. Peng
Examples
Description
These functions form the interface for a simple file-based key-value database (i.e. hash table).
Slots
Methods
dbDelete The dbDelete function is for deleting elements, but for the "DB1" format all it does is
remove the key from the lookup table. The actual data are still in the database (but inacces-
sible). If you reinsert data for the same key, the new data are simply appended on to the end
of the file. Therefore, it’s possible to have multiple copies of data lying around after a while,
potentially making the database file big. The "RDS" format does not have this problem.
dbExists check to see if a key exists.
dbFetch retrieve the value associated with a given key.
dbMultiFetch retrieve values associated with multiple keys (a list of those values is returned).
dbInsert insert a key-value pair into the database. If that key already exists, its associated value is
overwritten. For "RDS" type databases, there is a safe option (defaults to TRUE) which allows
the user to insert objects somewhat more safely (objects should not be lost in the event of an
interrupt).
dbList list all keys in the database.
dbReorganize The dbReorganize function is there for the purpose of rewriting the database to
remove all of the stale entries. Basically, this function creates a new copy of the database and
then overwrites the old copy. This function has not been tested extensively and so should be
considered experimental. dbReorganize is not needed when using the "RDS" format.
dbUnlink delete an entire database from the disk
show print method
with allows with to be used with "filehash" objects much like it can be used with lists or data
frames
[[,[[<- elements of a database can be accessed using the [[ operator much like a list or environment,
but only character indices are allowed
$,$<- elements of a database can be accessed using the $ operator much like with a list or environ-
ment
lapply works much like lapply with lists; a list is returned.
names returns all of the keys in the database
length returns the number of elements in the database
Author(s)
Roger D. Peng <[email protected]>
Examples
dbCreate("myDB") ## Create database ’myDB’
db <- dbInit("myDB")
dbInsert(db, "a", 1:10)
dbInsert(db, "b", rnorm(1000))
dbExists(db, "b") ## ’TRUE’
with(db, mean(b))
Description
List and register filehash backend database formats.
Usage
registerFormatDB(name, funlist)
filehashFormats(...)
Arguments
name character, name of database format
funlist list of functions for creating and initializing a database format
... list of functions for registering a new database format
Details
registerFormatDB can be used to register new filehash backend database formats. filehashFormats
called with no arguments lists information on available formats.
Value
filehashFormats returns a list containing information on the available filehash formats.
Description
Set global filehash options
Usage
filehashOption(...)
Arguments
... name-value pairs for options
10 queue-class
Details
Currently, the only option that can be set is the default database type (defaultType) which can be
"DB1", "RDS" or "DB".
Value
filehashOptions returns a list of current settings for all options.
Author(s)
Roger D. Peng
Description
A queue implementation using a filehash database
Slots
queue: Object of class "filehashDB1"
name: Object of class "character": the name of the queue (default is the file name in which the
queue data are stored)
Methods
isEmpty signature(db = "queue"): returns TRUE/FALSE depending on whether there are ele-
ments in the queue.
pop signature(db = "queue"): returns the value of the "top" (i.e. head) of the queue and sub-
sequently removes that element from the queue; an error is signaled if the queue is empty
push signature(db = "queue"): adds an element to the tail ("bottom") of the queue
show signature(object = "queue"): prints the name of the queue
top signature(db = "queue"): returns the value of the "top" (i.e. head) of the queue; an error is
signaled if the queue is empty
Author(s)
Roger D. Peng <[email protected]>
Examples
showClass("queue")
stack-class 11
Description
Objects can be created by calls of the form new("stack", ...) or by calling createS. Existing
queues can be initialized with initS.
Slots
Methods
isEmpty signature(db = "stack"): returns TRUE/FALSE depending on whether there are ele-
ments in the stack.
pop signature(db = "stack"): returns the value of the top of the stack and subsequently re-
moves that element from the stack; an error is signaled if the stack is empty
push signature(db = "stack"): adds an element to the top of the stack
show signature(object = "stack"): prints the name of the stack
top signature(db = "stack"): returns the value of the top of the stack; an error is signaled if
the stack is empty
mpush signature(db = "stack"): works like push except it can push multiple objects in a list
on to the stack
Author(s)
Examples
showClass("stack")
12 stackqueue
Description
Functions for interacting with stack and queue data structures implemented using filehash databases.
Usage
push(db, val, ...)
mpush(db, vals, ...)
pop(db, ...)
top(db, ...)
isEmpty(db, ...)
Arguments
db an object of class "stack" or "queue"
val an R object
vals a list of R objects
... arguments passed to other methods
Details
Note that for mpush, if vals is not a list it will be coerced to a list via as.list. Currently, mpush is
only implemented for "stack"s.
Value
push and mpush return nothing useful; pop returns a value from the stack/queue and deletes that
value from the stack/queue; top returns the "top" value from the stack/queue; isEmpty returns
TRUE/FALSE depending on whether the stack/queue is empty or not. Both pop and top signal an
error if the stack/queue is empty.
Author(s)
Roger D. Peng <[email protected]>
Index
13
14 INDEX
dbList,filehashDB-method lapply,filehash-method
(filehash-class), 7 (filehash-class), 7
dbList,filehashDB1-method length,filehash-method
(filehash-class), 7 (filehash-class), 7
dbList,filehashRDS-method
(filehash-class), 7 mpush (stackqueue), 12
dbLoad, 4 mpush,stack-method (stack-class), 11
dbLoad,filehash-method (dbLoad), 4
names,filehash-method (filehash-class),
dbMultiFetch (filehash-class), 7
7
dbMultiFetch,filehashDB1,character-method
(filehash-class), 7 pop (stackqueue), 12
dbMultiFetch,filehashDB1-method pop,queue-method (queue-class), 10
(filehash-class), 7 pop,stack-method (stack-class), 11
dbMultiFetch,filehashRDS,character-method push (stackqueue), 12
(filehash-class), 7 push,queue-method (queue-class), 10
dbReconnect (dbInit), 3 push,stack-method (stack-class), 11
dbReconnect,filehashDB1-method
(dbInit), 3 queue-class, 10
dbReorganize (filehash-class), 7
dbReorganize,filehashDB-method registerFormatDB (filehashFormats), 9
(filehash-class), 7
dbReorganize,filehashDB1-method show,filehash-method (filehash-class), 7
(filehash-class), 7 show,queue-method (queue-class), 10
dbUnlink (filehash-class), 7 show,stack-method (stack-class), 11
dbUnlink,filehashDB-method stack-class, 11
(filehash-class), 7 stackqueue, 12
dbUnlink,filehashDB1-method
top (stackqueue), 12
(filehash-class), 7
top,queue-method (queue-class), 10
dbUnlink,filehashRDS-method
top,stack-method (stack-class), 11
(filehash-class), 7
dumpDF (dumpObjects), 6 with,filehash-method (filehash-class), 7
dumpEnv (dumpObjects), 6
dumpImage (dumpObjects), 6
dumpList (dumpObjects), 6
dumpObjects, 6
filehash-class, 7
filehashDB-class (filehash-class), 7
filehashDB1-class (filehash-class), 7
filehashFormats, 9
filehashOption, 4, 9
filehashRDS-class (filehash-class), 7
initQ (createQ), 2
initS (createS), 2
isEmpty (stackqueue), 12
isEmpty,queue-method (queue-class), 10
isEmpty,stack-method (stack-class), 11