Load entire database into an environment
1 2 3 4 5 6 7 8
character vector of database keys to load
other arguments passed to methods
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.
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
The use of
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.
dbLazyLoad database objects are
"lazy-loaded" into the environment. Promises to load the
objects are created in the environment specified by
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
db2env, an environment is returned, the elements of which
are the keys of the database. For
dbLazyLoad, a character vector
is returned (invisibly) containing the keys associated with the values
loaded into the environment.
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
dbCreate("myDB") db <- dbInit("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) env <- new.env() dbLoad(db, env) ls(env) env <- new.env() dbLazyLoad(db, env) ls(env) as(db, "list")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.