From b69f4e15c239969dc43f1c6b27ba2123200aa314 Mon Sep 17 00:00:00 2001 From: Paul Bastide Date: Tue, 27 Feb 2024 16:39:43 +0100 Subject: [PATCH] Not in parallel when ncores is one. --- R/phylogeneticCorrelations.R | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/R/phylogeneticCorrelations.R b/R/phylogeneticCorrelations.R index b4b87c8..0469c8c 100644 --- a/R/phylogeneticCorrelations.R +++ b/R/phylogeneticCorrelations.R @@ -155,12 +155,17 @@ get_consensus_tree <- function(y_data, design, phy, model, measurement_error, we starting_values <- get_starting_values(alpha_bounds, ...) dots_args <- get_dots_args(...) - cl <- parallel::makeCluster(ncores) # , outfile = "" - doParallel::registerDoParallel(cl) - on.exit(parallel::stopCluster(cl)) + if (ncores > 1) { + cl <- parallel::makeCluster(ncores) # , outfile = "" + doParallel::registerDoParallel(cl) + on.exit(parallel::stopCluster(cl)) + `%myinfix%` <- `%dopar%` + } else { + `%myinfix%` <- `%do%` + } reqpckg <- c("phylolm") - all_fits <- foreach::foreach(i = 1:nrow(y_data), .packages = reqpckg) %dopar% { + all_fits <- foreach::foreach(i = 1:nrow(y_data), .packages = reqpckg) %myinfix% { y <- y_data[i, ] # w <- weights[i, ]