sapply()
Apply a function to a vector using parallel processing.
pSapply(
X,
FUN,
parallel = c("snow", "multicore", "no"),
ncpus = NULL,
cl = NULL,
add.obj = NULL,
...
)
The output of FUN
in a list, or simplified to a vector or array.
A vector object (numeric, character, or list).
Function to apply to the elements of X
.
The type of parallel processing to use. Can be one of
"snow"
(default), "multicore"
(not available on Windows), or "no"
(for none). See Details.
Number of system cores to use for parallel processing. If NULL
(default), all available cores are used.
Optional cluster to use if parallel = "snow"
. If NULL
(default), a local cluster is created using the specified number of cores.
A character vector of any additional object names to be exported to the cluster. Use if a required object or function cannot be found.
Additional arguments to parSapply()
,
mcmapply()
, or
sapply()
(note: arguments "simplify"
and "SIMPLIFY"
are both
allowed).
This is a wrapper for parallel::parSapply()
("snow"
) or
parallel::mcmapply()
("multicore"
), enabling (potentially) faster processing of a function
over a vector of objects. If parallel = "no"
, sapply()
is used instead.
Parallel processing via option "snow"
(default) is carried out using a
cluster of workers, which is automatically set up via makeCluster()
using
all available system cores or a user supplied number of cores. The function
then exports the required objects and functions to this cluster using
clusterExport()
, after performing a (rough) match of all objects and
functions in the current global environment to those referenced in the call
to FUN
(and also any calls in X
). Any additional required object names
can be supplied using add.obj
.