chunkToLineReader           package:RCurl           R Documentation

_U_t_i_l_i_t_y _t_h_a_t _c_o_l_l_e_c_t_s _d_a_t_a _f_r_o_m _t_h_e _H_T_T_P _r_e_p_l_y _i_n_t_o _l_i_n_e_s _a_n_d
_c_a_l_l_s _u_s_e_r-_p_r_o_v_i_d_e_d _f_u_n_c_t_i_o_n.

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

     When one provides an R function to process the body of the R rep

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

     chunkToLineReader(f, verbose = FALSE)

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

       f: a function that is to be called each time the 'read' function
          is invoked and there are complete lines in that input.

 verbose: a logical value. If 'TRUE', information is displayed when
          there is any text that does not form a complete line and is
          held for processing in the next chunk. 

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

     This constructs a closure and then processes each chunk as they
     are passed to the read function. It strips away any text that does
     not form a complete line at the end of the chunk and holds this to
     be added to the next chunk being processed.

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

     A list with two components 

    read: the function that will do the actual reading from the HTTP
          response stream and call the function 'f' on each step
          (assuming the chunk has a line marker.

  comp2 : Description of 'comp2'

     ...

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

     Duncan Temple Lang <duncan@wald.ucdavis.edu>

_R_e_f_e_r_e_n_c_e_s:

     Curl homepage <URL: http://curl.haxx.se>

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

     'getURI' and the 'write' argument. 'getForm', 'postForm'  
     'curlPerform'

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

     # Read a rectangular table of data into R from the URL
     # and add up the values and the number of values read.

     summer =
     function()
     {
       total = 0.0
       numValues = 0

       list(read = function(txt) {
                      con = textConnection(txt)
                      on.exit(close(con))
                      els = scan(con)
                      numValues <<- numValues + length(els)
                      total <<- total + sum(els)

                      ""
                   },
            result = function() c(total = total, numValues = numValues))
     }

     s = summer()

     getURL("http://www.omegahat.org/RCurl/matrix.data", write = chunkToLineReader(s$read)$read)

