Skip to content

Commit

Permalink
Silence messages written by FUN to STDOUT #59
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Solymos <psolymos@gmail.com>
  • Loading branch information
psolymos committed Dec 10, 2022
1 parent 4645374 commit ed40554
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions R/pblapply.R
Expand Up @@ -64,20 +64,24 @@ function (X, FUN, ..., cl = NULL)
requireNamespace("future")
requireNamespace("future.apply")
if (!dopb())
return(future.apply::future_lapply(X, FUN, ...))
return(future.apply::future_lapply(X, FUN, ...,
future.stdout = FALSE))
Split <- splitpb(length(X), future::nbrOfWorkers(), nout = nout)
B <- length(Split)
pb <- startpb(0, B)
on.exit(closepb(pb), add = TRUE)
rval <- vector("list", B)
for (i in seq_len(B)) {
rval[i] <- list(future.apply::future_lapply(X[Split[[i]]], FUN, ...))
rval[i] <- list(future.apply::future_lapply(X[Split[[i]]], FUN, ...,
future.stdout = FALSE))
setpb(pb, i)
}
## multicore type forking
} else {
if (!dopb())
return(parallel::mclapply(X, FUN, ..., mc.cores = as.integer(cl)))
return(parallel::mclapply(X, FUN, ...,
mc.cores = as.integer(cl),
mc.silent = TRUE))
## define split here and use that for counter
Split <- splitpb(length(X), as.integer(cl), nout = nout)
B <- length(Split)
Expand All @@ -86,7 +90,8 @@ function (X, FUN, ..., cl = NULL)
rval <- vector("list", B)
for (i in seq_len(B)) {
rval[i] <- list(parallel::mclapply(X[Split[[i]]], FUN, ...,
mc.cores = as.integer(cl)))
mc.cores = as.integer(cl),
mc.silent = TRUE))
setpb(pb, i)
}
}
Expand Down

0 comments on commit ed40554

Please sign in to comment.