gapply: Repeatedly apply a function over a grid of values in parallel

Description Usage Arguments Details Value Functions Examples

Description

gapply (grid apply) applies a function to a grid of it's parameters in parallel, optionally for a given number of replications

Usage

1
2
3
4
5
gapply(.f, ..., .reps = 1, .args = NULL, .mc.cores = 1, .verbose = 1,
  .eval = T, .stack = FALSE)

grid_apply(.f, ..., .reps = 1, .args = NULL, .mc.cores = 1,
  .verbose = 1, .eval = T, .paramid = NULL)

Arguments

.f

function to be evaluated. The function must return a (named) value or (named) vector of values.

...

named arguments to f in the form key=c(value1,value2, ...) etc. A grid of parameter values will be generated from values given to each named argument, as expand.grid(...)

.reps

times the function should be evaluated

.args

list of extra arguments to .f not included in the argument grid.

.mc.cores

attempts to split function evaluations over given number of cores

.verbose

If 1 (default), prints a . with every completed condition. If 2, prints the arguments corresponding to the completed condition. If 3, prints the arguments and results of the completed condition.

.eval

If TRUE (default), evaluates f. If FALSE, does not evaluate f and returns NA for value.

.stack

whether results should be stacked (see tidy)

.paramid

The index of the row of the argument grid to run. If NULL (default), .f is evaluated for all arguments.

Details

The attributes of the object include grid (the grid of parameter values), time (elapsed time), and err (list of errors).

The function application to each combination of meta-parameters (not replications) are distributed in parallel via mclapply and will not work in Windows.

Value

Returns results as a data.frame in long form with the following columns:

...

Columns corresponding to grid of parameters given in expand.grid(...)

.rep

the replication number

value

the value of f at a set of parameters, if .eval = FALSE, returns NA

Errors are captured using try, converted to character, and available using attr(object, "err")

Functions

Examples

1
2
do.one <- function(a=1,b=2){c(sum=a+b,sub=a-b)}
gapply(do.one, a=1:4,b=2:3, .reps=5)

patr1ckm/distributr documentation built on May 24, 2019, 8:21 p.m.