Learn R Programming

batchtools (version 0.9.0)

reduceResults: Reduce Results

Description

A version of Reduce for Registry objects which iterates over finished jobs and aggregates them.

Usage

reduceResults(fun, ids = NULL, init, ..., reg = getDefaultRegistry())

Arguments

fun
[function] A function to reduce the results. The result of previous iterations (or the init) will be passed as first argument, the result of of the i-th iteration as second. See Reduce for some examples. If the function has the formal argument “job”, the Job/Experiment is also passed to the function.
ids
[data.frame or integer] A data.frame (or data.table) with a column named “job.id”. Alternatively, you may also pass a vector of integerish job ids. If not set, defaults to the return value of findDone.
init
[ANY] Initial element, as used in Reduce. Default is the first result.
...
[ANY] Additional arguments passed to to function fun.
reg
[Registry] Registry. If not explicitly passed, uses the default registry (see setDefaultRegistry).

Value

Aggregated results in the same order as provided ids. Return type depends on the user function. If ids is empty, reduceResults returns init (if available) or NULL otherwise.

See Also

Other Results: batchMapResults, loadResult, reduceResultsList

Examples

Run this code
tmp = makeRegistry(file.dir = NA, make.default = FALSE)
batchMap(function(x) x^2, x = 1:10, reg = tmp)
submitJobs(reg = tmp)
waitForJobs(reg = tmp)
reduceResults(function(x, y) c(x, y), reg = tmp)
reduceResults(function(x, y) c(x, sqrt(y)), init = numeric(0), reg = tmp)

Run the code above in your browser using DataLab