cache                package:RbcBook1                R Documentation

_c_a_c_h_e _a_n _R _e_x_p_r_e_s_s_i_o_n _t_o _u_s_e _t_h_e _r_e_s_u_l_t _w_i_t_h_o_u_t
_r_e_c_o_m_p_u_t_a_t_i_o_n _i_n _l_a_t_e_r
_S_w_e_a_v_e _e_v_e_n_t_s

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

     cache an R expression to use the result without recomputation in
     later Sweave events

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

     cache(name, expr)

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

    name: character variable

    expr: R expression

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

     If the object 'tmp-[name].Rdata' does not exist, 'expr' is
     evaluated and written to 'tmp-[name].Rdata'. Otherwise,
     'tmp-[name].Rdata' is loaded and assigned to '[name]'.

     Note that if a graph is produced as a side effect of the cached
     command, it will not be produced when the cached object is
     encountered in future weavings. To avoid this problem, explicitly
     create the graphics output so that it persists and can be reused
     on future weavings.  In general this process should be avoided by
     making all graphical activities explicit, not byproducts of
     expensive calculations that are likely to be cached. In other
     words, all expensive calculations for which visualizations are of
     interest should return an object for which a plotting method is
     defined.  The object calculation can be cached and the plotting
     method can be applied to the cached object.

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

     The value of 'expr'.

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

     Wolfgang Huber <w.huber@dkfz.heidelberg.de>

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

     library(graph)
     unix.time(cache("bigran", randomGraph(paste("a", 1:100), 1:20, .3)))
     dir()
     unix.time(cache("bigran", randomGraph(paste("a", 1:100), 1:20, .3)))

