麻烦 运行 mc_replicate Windows

Trouble running mc_replicate on Windows

我在 Windows (10) 上遇到了一些问题 运行 mc_replicate(来自 mcreplicate 库)。我在 8 核机器上使用 R v. 4.1.1。当我尝试执行此代码时:

x1 <- mc_replicate(10000, runRandomLot(), mc.cores = 8,
                    envir = environment(), varlist = "runRandomLot",
                    packages = c("dplyr","magrittr"))

我收到这个错误:

Running parallel code on Windows: a parallel socket cluster will be used.

Variables and packages needed for code execution must be explicitely specified.

See the help file for more information and current defaults.


Error in checkForRemoteErrors(val) (ImplantGapRA.R#76): 8 nodes produced errors; first error: could not find function "%>%"

错误表明 magrittr 包没有被传递,但文档没有提供关于如何传递包的明确指导(如果这是问题所在)。任何关于如何更正我对 mc_replicate 的呼叫的指导将不胜感激。

首先,是的,我希望指定 packages = "magrittr" 可以解决这个问题,但我对 mcreplicate::mc_replicate()mcreplicate. Second, and more importantly, I peeked at the code 经验为零,令人担忧的是它没有设置建立适当的并行随机数生成 (RNG),这意味着您从并行工作人员获得的结果可能是相关的,尽管您希望 replicate() 调用为您提供适当的随机数。

(免责声明:我是作者)。如果您有使用 basereplicate() 的工作代码,我建议您将其原样替换为 future_replicate() of the future.apply 包以进行并行化。类似于:

library(future.apply)
plan(multisession, workers = 8)  ## Parallelize on 8 local workers

x1 <- future_replicate(10000, runRandomLot())

就是这样。