dbLoad               package:filehash               R Documentation

_L_o_a_d _d_a_t_a_b_a_s_e _i_n_t_o _e_n_v_i_r_o_n_m_e_n_t

_D_e_s_c_r_i_p_t_i_o_n:

     Load entire database into an environment

_U_s_a_g_e:

     db2env(db)
     dbLoad(db, ...)
     dbLazyLoad(db, ...)

     ## S4 method for signature 'filehash':
     dbLoad(db, env = parent.frame(2), keys = NULL, ...)
     ## S4 method for signature 'filehash':
     dbLazyLoad(db, env = parent.frame(2), keys = NULL, ...)

_A_r_g_u_m_e_n_t_s:

      db: database object

     env: an environment

    keys: character vector of database keys to load

     ...: other arguments passed to methods

_D_e_t_a_i_l_s:

     '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 '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.

_V_a_l_u_e:

     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.

_A_u_t_h_o_r(_s):

     Roger D. Peng

_S_e_e _A_l_s_o:

     'dbInit' and 'filehash-class'

_E_x_a_m_p_l_e_s:

     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)

