dbApply                package:RMySQL                R Documentation

_A_p_p_l_y _R/_S _f_u_n_c_t_i_o_n_s _t_o _r_e_m_o_t_e _g_r_o_u_p_s _o_f _D_B_M_S _r_o_w_s (_e_x_p_e_r_i_m_e_n_t_a_l)

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

     Applies R/S functions to groups of remote DBMS rows without
     bringing an entire result set all at once.  The result set is
     expected to be sorted by the grouping field. (Currently only
     implemented by the MySQL driver.)

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

     dbApply(rs, ...)

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

      rs: a result set (see `dbExec').

     ...: any additional arguments to be used by the driver code.

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

     `dbApply'  This function is meant to handle somewhat gracefully(?)
     large amounts  of data from the DBMS by bringing into R manageable
     chunks (about  `batchSize' records at a time, but not more than
     `maxBatch');  the idea is that the data from individual groups can
     be handled by R, but not all the groups at the same time.  

     For details see the driver's `dbApply' method, e.g., 
     `dbApply.MySQLResultSet'.

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

     A list with as many elements as there were groups in the result
     set.

_N_o_t_e:

     This is an experimental version.

     The terminology that we're using is closer to SQL than R.  In R
     what we're referring to ``groups'' are the individual levels of a
     factor (grouping field in our terminology).

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

     `MySQL', `dbExec', `fetch'.

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

     ## compute quanitiles for each network agent
     con <- dbConnect(MySQL(), group="vitalAnalysis")
     rs <- dbExec(con, 
                  "select Agent, ip_addr, DATA from pseudo_data order by Agent")
     out <- dbApply(rs, INDEX = "Agent", 
             FUN = function(x, grp) quantile(x$DATA, names=F))

