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)))

