Learn R Programming

RMySQL (version 0.4-6)

dbApply: Apply R/S functions to remote groups of DBMS rows (experimental)

Description

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

Usage

dbApply(rs, ...)

Arguments

rs
a result set (see dbExec).
...
any additional arguments to be used by the driver code.

Value

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

Details

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.

See Also

MySQL, dbExec, fetch.

Examples

Run this code
## 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))

Run the code above in your browser using DataLab