Description Usage Arguments Details Value See Also
Parallelize applying a function over a list or vector according to the registered parallelization engine.
1 2 | tm_parLapply(X, FUN, ...)
tm_parLapply_engine(new)
|
X |
A vector (atomic or list), or other objects suitable for the engine in use. |
FUN |
the function to be applied to each element of |
... |
optional arguments to |
new |
an object inheriting from class |
Parallelization can be employed to speed up some of the embarrassingly
parallel computations performed in package tm, specifically
tm_index()
, tm_map()
on a non-lazy-mapped
VCorpus
, and TermDocumentMatrix()
on a
VCorpus
or PCorpus
.
Functions tm_parLapply()
and tm_parLapply_engine()
can
be used to customize parallelization according to the available
resources.
tm_parLapply_engine()
is used for getting (with no arguments)
or setting (with argument new
) the parallelization engine
employed (see below for examples).
If an engine is set to an object inheriting from class cluster
,
tm_parLapply()
calls
parLapply()
with this cluster and
the given arguments. If set to a function, tm_parLapply()
calls the function with the given arguments. Otherwise, it simply
calls lapply()
.
Hence, parallelization via
parLapply()
and a default cluster registered via
setDefaultCluster()
can be
achieved via
1 2 |
or re-registering the cluster, say cl
, using
1 |
(note that since R version 3.5.0, one can use
getDefaultCluster()
to get
the registered default cluster). Using
1 2 | tm_parLapply_engine(function(X, FUN, ...)
parallel::parLapplyLB(NULL, X, FUN, ...))
|
or
1 2 | tm_parLapply_engine(function(X, FUN, ...)
parallel::parLapplyLB(cl, X, FUN, ...))
|
gives load-balancing parallelization with the registered default or
given cluster, respectively. To achieve parallelization via forking
(on Unix-alike platforms), one can use the above with clusters created
by makeForkCluster()
, or use
1 |
or
1 2 |
to use mclapply()
with the default or
given number n
of cores.
A list the length of X
, with the result of applying FUN
together with the ...
arguments to each element of X
.
makeCluster()
,
parLapply()
,
parLapplyLB()
, and
mclapply()
.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.