capture                package:gtools                R Documentation

_C_a_p_t_u_r_e _p_r_i_n_t_e_d _o_u_t_p_u_t _o_f _a_n _R _e_x_p_r_e_s_s_i_o_n _i_n _a _s_t_r_i_n_g

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

     Capture printed output of an R expression in a string

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

     capture(expression, collapse = "\n")
     sprint(x,...)

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

expression: R expression whose output will be captured.

collapse: Character used to join output lines.  Defaults to "\n".  Use
          'NULL' to return a vector of individual output lines.

       x: Object to be printed

     ...: Optional parameters to be passed to 'print' 

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

     The 'capture' function uses 'sink' to capture the printed results
     generated by 'expression'. 

     The function 'sprint' uses 'capture' to redirect the results of
     calling 'print' on an object to a string.

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

     A character string, or if 'collapse==NULL' a vector of character
     strings containing the printed output from the R expression.

_W_A_R_N_I_N_G:

     R 1.7.0+ includes 'capture.output', which duplicates the
     functionality of 'capture'.  Thus, 'capture' is depreciated.

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

     Gregory R. Warnes warnes@bst.rochester.edu

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

     'texteval', 'capture.output'

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

     # capture the results of a loop
     loop.text <- capture( for(i in 1:10) cat("i=",i,"\n") )
     loop.text

     # put regression summary results into a string
     data(iris)
     reg <- lm( Sepal.Length ~ Species, data=iris )
     summary.text <- sprint( summary(reg) )
     cat(summary.text)

