gpt4 book ai didi

使用并行功能时 R CRAN 检查失败

转载 作者:行者123 更新时间:2023-12-01 12:33:02 24 4
gpt4 key购买 nike

我想使用 parallel::makeCluster(parallel::detectCores()) 向 CRAN 提交一个使用并行计算的包.

当我构建包时一切正常,但是当我检查包( devtools::check(document = FALSE) )时,它返回错误:

Running examples in ‘TESTER-Ex.R’ failed
The error most likely occurred in:

> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: hello_world
> ### Title: Prints hello world
> ### Aliases: hello_world
>
> ### ** Examples
>
> hello_world()
Error in .check_ncores(length(names)) : 8 simultaneous processes spawned
Calls: hello_world -> <Anonymous> -> makePSOCKcluster -> .check_ncores
Execution halted

我在 MWE 包 (TESTER) 中重新创建了错误,它只有一个功能 hello_world ,我已经上传了全文 TESTER-package到 GitHub,但它应该可以从以下函数中重现。
#' Prints hello world
#'
#' @return nothing
#' @export
#'
#' @examples
#' hello_world()
hello_world <- function() {

# initiate cluster
cl <- parallel::makeCluster(parallel::detectCores())

# stop cluster
parallel::stopCluster(cl)

cat("Hello World\n")
return(invisible(NULL))
}

我浏览过 Writing R Extensions但找不到与此问题相关的任何内容,我也找不到关于 SO 的问题。

任何想法导致此错误以及如何解决它?

最佳答案

CRAN 将可用于封装的内核数量限制为 2,
出于性能原因。
邮件列表中有一个线程,
我相信,
但我现在找不到。

我在测试中使用类似以下内容:

chk <- Sys.getenv("_R_CHECK_LIMIT_CORES_", "")

if (nzchar(chk) && chk == "TRUE") {
# use 2 cores in CRAN/Travis/AppVeyor
num_workers <- 2L
} else {
# use all cores in devtools::test()
num_workers <- parallel::detectCores()
}

关于使用并行功能时 R CRAN 检查失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50571325/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com