Description Usage Arguments Value Lifecycle Examples
View source: R/overload_mclapply.R
Enable the use of bettermc::mclapply
by
third-party packages originally using mclapply
from the parallel
package, e.g. doMC or rstan. This is achieved by replacing the
mclapply
-function in various environments.
undo_overload_mclapply
re-installs the original
parallel::mclapply
.
1 2 3 4 5 6 7 8 9 10 11 12 13 | overload_mclapply(
parallel_namespace = FALSE,
parallel_package = FALSE,
imports = character(),
defaults = list(),
fixed_args = list()
)
undo_overload_mclapply(
parallel_namespace = FALSE,
parallel_package = FALSE,
imports = character()
)
|
parallel_namespace |
should |
parallel_package |
should |
imports |
the name of packages for which |
defaults |
a list named by one or more of the formal arguments of
|
fixed_args |
a list named by one or more of the formal arguments of
|
These functions return NULL invisibly and are called for their side effects.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | if (tolower(Sys.info()[["sysname"]]) != "windows") {
doMC::registerDoMC(2L)
# fix mc.set.seed arg to NA in order to avoid modifications by doMC:::doMC
overload_mclapply(imports = "doMC", fixed_args = list(mc.set.seed = NA))
set.seed(123)
ret1 <- foreach::`%dopar%`(foreach::foreach(i = 1:4), runif(1))
set.seed(123)
ret2 <- foreach::`%dopar%`(foreach::foreach(i = 1:4), runif(1))
stopifnot(identical(ret1, ret2))
undo_overload_mclapply(imports = "doMC")
# back to using parallel::mclapply under the hood -> seeding has no effect
set.seed(123)
ret1 <- foreach::`%dopar%`(foreach::foreach(i = 1:4), runif(1))
set.seed(123)
ret2 <- foreach::`%dopar%`(foreach::foreach(i = 1:4), runif(1))
stopifnot(!identical(ret1, ret2))
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.