Learn R Programming

filehash (version 0.2-1)

db2env: Load database into environment

Description

Load entire database into an environment

Usage

db2env(db)

Arguments

db
database object

Value

  • An environment is returned, the elements of which are the keys of the database.

Details

db2env is generic but there is a method for objects of class "filehash". db2env loads the entire database db into an environment via calls to makeActiveBinding. Therefore, 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.

The use of makeActiveBinding 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.

See Also

dbUtils and filehash-class

Examples

Run this code
dbCreate("myDB")
db <- dbInitialize("myDB")
dbInsert(db, "a", rnorm(100))
dbInsert(db, "b", 1:10)

env <- db2env(db)
ls(env)  ## "a", "b"
print(env$b)
mean(env$a)
env$a <- rnorm(100)
mean(env$a)

env$b[1:5] <- 5:1
print(env$b)

Run the code above in your browser using DataLab