Skip to content

Commit

Permalink
tweak check + use of parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinushey committed Sep 25, 2024
1 parent 6fd4f16 commit 6b0503f
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions R/parallel.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@ renv_parallel_cores <- function() {
return(1L)

value <- config$updates.parallel()
case(
identical(value, TRUE) ~ getOption("mc.cores", default = 2L),
identical(value, FALSE) ~ 1L,
~ as.integer(value)
)
if (identical(value, TRUE)) {
parallel <- requireNamespace("parallel", quietly = TRUE)
getOption("mc.cores", default = if (parallel) 2L else 1L)
} else if (identical(value, FALSE)) {
1L
} else {
as.integer(value)
}

}

renv_parallel_exec <- function(data, callback) {
cores <- renv_parallel_cores()
if (cores > 1)
if (cores > 1L)
parallel::mclapply(data, callback, mc.cores = cores)
else
lapply(data, callback)
Expand Down

0 comments on commit 6b0503f

Please sign in to comment.