texteval               package:session               R Documentation

_E_v_a_l_u_a_t_e _s_t_r_i_n_g(_s) _c_o_n_t_a_i_n_i_n_g _R _c_o_m_m_a_n_d_s _a_n_d _r_e_t_u_r_n _t_h_e _t_e_x_t
_t_r_a_n_s_c_r_i_p_t _o_r _p_r_i_n_t_e_d _r_e_s_u_l_t_s

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

     Evaluate string(s) containing R commands and return the text
     transcript or printed results

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

     capture(expression, collapse=NULL)
     texteval(sourceText, collapse=NULL, echo=TRUE)
     printed(sourceText, collapse=NULL)

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

expression: R expression to be evaluated 

sourceText: Vector of string to be evaluated.  

collapse: Line separator. Defaults to 'NULL' 

    echo: Should commands be shown in output. Defaults to 'TRUE' 

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

     'capture' captures the results of executing 'expression' using a
     'textConnection'. 'texteval' and 'printed' parse and evaluate the
     contents of sourceText using 'source' and the results are captured
     using a 'textConnection'.  If 'collapse' is NULL, a vector of
     strings is returned, one element for each line of output. (Empty
     strings for blank lines).  If 'collapse' is non-NULL, the a single
     character string is formed by pasting the individuals elements
     together separated by this value.  When 'echo' is TRUE, 'texteval'
     will return a transcript that includes both printed output and
     evaluated commands. When 'echo' is FALSE, 'texteval' will return
     only the printed output.  'printed' always returns only the
     printed output.

     These functions were created to allow strings provided from
     external processes (for example by rpy or RSPerl) to be evaluated
     as if they were scripts.

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

     A single character string if 'collapse' is non-NULL, otherwise a
     vector of character strings.

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

     Gregory R. Warnes warnes@bst.rochester.edu

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

     'source', 'textConnection', 'sink', 'parse', 'eval'

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

     # define a script string
     script <- "x <- rnorm(100)\ny <- x + rnorm(100,0.25)\nsummary(lm(y~x))"

     # evaluate the script string, returning a transcript.
     result <- texteval(script, "\n")
     cat(result)

     # evaluate the script string, returning the printed output.
     result <- printed(script, "\n")
     cat(result)

