From 43dc43ae4bcb7dfb62e674ec8d91f77078ad1770 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Holger=20L=C3=B6we?= <64039523+holgstr@users.noreply.github.com> Date: Thu, 11 Jan 2024 19:57:36 +0100 Subject: [PATCH] Add feedback from future devs (#106) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #105 --------- Signed-off-by: Holger Löwe <64039523+holgstr@users.noreply.github.com> Co-authored-by: Daniel Sabanes Bove --- NEWS.md | 1 + R/corPFSOS.R | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 474ccbb3..f2649de4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -11,6 +11,7 @@ - `WeibSurvOS` now does not return an error for large values of t. - `PWCSurvOS` now does not return an error for large values of t. It also no longer returns values larger than 1. It is significantly faster, based on a closed form calculation instead of numerical integration. - `getSimulatedData` now also works when there are no transitions from progression to death, similarly for `getOneClinicalTrial` (which now warns if there are no such transitions at all). +- `corPFSOS` now undoes the `future` plan upon function exit. ### Miscellaneous diff --git a/R/corPFSOS.R b/R/corPFSOS.R index 25e16974..38d71320 100644 --- a/R/corPFSOS.R +++ b/R/corPFSOS.R @@ -314,7 +314,8 @@ corPFSOS <- function(data, transition, bootstrap = TRUE, bootstrap_n = 100, conf trans <- estimateParams(data, transition) res <- list("corPFSOS" = corTrans(trans)) if (bootstrap) { - future::plan(future::multisession, workers = max(1, parallelly::availableCores() - 1)) + oplan <- future::plan(future::multisession, workers = parallelly::availableCores(omit = 1)) + on.exit(future::plan(oplan), add = TRUE) ids <- lapply(1:bootstrap_n, function(x) sample(seq_len(nrow(data)), nrow(data), replace = TRUE)) corBootstrap <- furrr::future_map_dbl(ids, ~ { furrr::furrr_options(