db.lapply: Apply a function to rows in a result set

View source: R/db-eval.R

db.lapplyR Documentation

Apply a function to rows in a result set

Description

Apply a function to rows in a result set

Usage

db.lapply(db, stmt, params, FUN, ...)

Arguments

db

The database connection. An S4 object of class "database".

stmt

The SQL statement to evaluate.

params

A matrix, data.frame, or list of lists with parameters.

FUN

The function to apply.

...

Additional arguments to FUN.

Details

Function FUN is called on each row returned by the query stmt. The first argument to FUN will be a named list containing the fields for a row returned by the stmt. Subsequent arguments to FUN are passed via ...

Value

A list, each element of which is the result of applying FUN to a row in the result set.

See Also

db.eval

Examples

db = db.open()
db.eval(db, "CREATE TABLE t(a REAL, b REAL)")
db.eval(db, "INSERT INTO t VALUES(?,?)", matrix(runif(200), 100, 2))
db.lapply(db, "SELECT * FROM t", FUN=function(r) sum(unlist(r)))

blueraleigh/db documentation built on Feb. 25, 2024, 9:13 a.m.