cache                package:Biobase                R Documentation

_E_v_a_l_u_a_t_e _a_n _e_x_p_r_e_s_s_i_o_n _i_f _i_t_s _v_a_l_u_e _i_s _n_o_t _a_l_r_e_a_d_y _c_a_c_h_e_d.

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

     Cache the evaluation of an expression in the file system.

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

         cache(expr, dir=".", prefix="tmp_R_cache_", name)

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

    expr: An expression of the form 'LHS <- RHS', Where 'LHS' is a
          variable name, 'RHS' is any valid expression, and '<-' must
          be used ('=' will not work).

     dir: A string specifying the directory into which cache files
          should be written (also where to go searching for an
          appropriate cache file).

  prefix: A string giving the prefix to use when naming and searching
          for cache files.  The default is '"tmp_R_cache_"'

    name: Unused.  This argument is present as a compatibility layer
          for the deprecated calling convention.

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

     This function can be useful during the development of
     computationally intensive workflows, for example in vignettes or
     scripts.  The function uses a cache file in 'dir' which defaults
     to the current working directory whose name is obtained by
     'paste(prefix, name, ".RData", sep="")'.

     When 'cache' is called and the cache file exists, it is loaded and
     the object whose name is given on the left of '<-' in 'expr' is
     returned.  In this case, 'expr' is _not_ evaluted.

     When 'cache' is called and the cache file does not exist, 'expr'
     is evaluted, its value is saved into a cache file, and then its
     value is returned.

     The 'expr' argument must be of the form of 'someVar <-
     {expressions}'.  That is, the left hand side must be a single
     symbol name and the next syntactic token must be '<-'.

     To flush the cache and force recomputation, simply remove the
     cache files.  You can use 'file.remove' to do this.

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

     The (cached) value of 'expr'.

_N_o_t_e:

     The first version of this function had a slightly different
     interface which is now deprecated (but still functional).  The old
     version has arguments 'name' and 'expr' and the intended usage is:
     'foo <- cache("foo", expr)'.

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

     Wolfgang Huber, huber@ebi.ac.uk Seth Falcon, sfalcon@fhcrc.org

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

         bigCalc <- function() runif(10)
         cache(myComplicatedObject <- bigCalc())
         aCopy <- myComplicatedObject
         remove(myComplicatedObject)
         cache(myComplicatedObject <- bigCalc())
         stopifnot(all.equal(myComplicatedObject, aCopy))
         allCacheFiles <- list.files(".", pattern="^tmp_R_cache_.*\.RData$",
                                     full.name=TRUE)
         file.remove(allCacheFiles)

