| srapply {ShortRead} | R Documentation |
This lapply like function evaluates locally or, if Rmpi
is loaded and workers spawned, across nodes in a cluster. Errors in
evaluation of FUN generate warnings; results are trimmed to
exclude results where the error occurs.
srapply(X, FUN, ..., fapply = .fapply(), reduce = .reduce(), verbose = FALSE)
X |
Tasks to be distributed. X should be an object for
which lapply or sapply are defined (more precisely,
mpi.parLapply, mpi.parSapply). Performance is best
when these objects are relatively small, e.g., file names, compared
to the work to be done on each by FUN. |
FUN |
A function to be applied to each element of X. The
function must have ... or named argument verbose in
its signature. It is best if it makes no reference to variables
other than those in its argument list. or in loaded packages (the
ShortRead package is available on remote nodes). |
... |
Additional arguments, passed to FUN. |
fapply |
An optional argument defining an lapply-like
function to be used in partitioning X. See details, below. |
reduce |
Optional function accepting a list (the result of
fapply and summarizing this. The default reports errors in
function evaluation as warnings, returning the remaining values as
elements of a list. See details below for additional hints. |
verbose |
Report whether evaluation is local or mpi-based; also
forwarded to FUN, allowing detailed reports from remote
instances. |
The default value for fapply is available with
ShortRead:::.fapply(). It tests whether Rmpi is loaded
and workers spawned. If so, the default ensures that ShortRead
is required on all workers, and then invokes
mpi.parLapply with arguments X, FUN,
..., and verbose. The function FUN is wrapped
so that errors are returned as objects of class SRError with
type RemoteError.
If no workers are available, the code evaluates FUN so that
errors are reported as with remote evaluation.
Custom reduce functions might be written as
reduce=function(lst) unlist(lst, use.names=TRUE).
The returned value depends on the value of reduce, but by
default is a list with elements containing the results of FUN
applied to each of X. Evaluations resulting in an error have
been removed, and a warning generated.
Martin Morgan <mtmorgan@fhcrc.org>
## ... or 'verbose' required in argument,
srapply(1:10, function(i, ...) i)
## collapse result to vector
srapply(1:10, function(i, ...) i, reduce=unlist)
x <- srapply(1:10, function(i, ...) {
if (runif(1)<.2) stop("oops") else i
})
length(x) ## trimmed to exclude errors