I want to submit a package to CRAN that uses parallel computation using parallel::makeCluster(parallel::detectCores())
.
When I build the package everything works fine, but when I check the package (devtools::check(document = FALSE)
) it returns the error:
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
I recreated the error in an MWE-package (TESTER), which only has one function hello_world
, I have uploaded the whole TESTER-package to GitHub but the it should be reproducible from the following function.
#' 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))
}
I have looked through Writing R Extensions but couldn't find anything related to this issue, neither could I find a question on SO.
Any ideas what causes this error and how to resolve it?