diff --git a/R/epinow.R b/R/epinow.R index 514845739..fe630e0d4 100644 --- a/R/epinow.R +++ b/R/epinow.R @@ -26,6 +26,7 @@ #' @examples #' \donttest{ #' # set number of cores to use +#' old_opts <- options() #' options(mc.cores = ifelse(interactive(), 4, 1)) #' # construct example distributions #' generation_time <- get_generation_time(disease = "SARS-CoV-2", source = "ganyani") @@ -54,6 +55,8 @@ #' #' # summary of R estimates #' summary(out, type = "parameters", params = "R") +#' +#' options(old_opts) #' } epinow <- function(reported_cases, generation_time = NULL, diff --git a/R/estimate_infections.R b/R/estimate_infections.R index 4d02c36a1..2865dbc1b 100644 --- a/R/estimate_infections.R +++ b/R/estimate_infections.R @@ -50,7 +50,9 @@ #' @examples #' \donttest{ #' # set number of cores to use +#' old_opts <- options() #' options(mc.cores = ifelse(interactive(), 4, 1)) +#' #' # get example case counts #' reported_cases <- example_confirmed[1:60] #' @@ -197,6 +199,8 @@ #' # random walk effects #' summary(rw, type = "parameters", params = "breakpoints") #' plot(rw) +#' +#' options(old_opts) #' } estimate_infections <- function(reported_cases, generation_time, diff --git a/R/estimate_secondary.R b/R/estimate_secondary.R index cba1ddf1f..93144a552 100644 --- a/R/estimate_secondary.R +++ b/R/estimate_secondary.R @@ -42,7 +42,9 @@ #' @examples #' \donttest{ #' # set number of cores to use +#' old_opts <- options() #' options(mc.cores = ifelse(interactive(), 4, 1)) +#' #' #' # load data.table for manipulation #' library(data.table) #' # load lubridate for dates @@ -135,6 +137,8 @@ #' # forecast future secondary cases from primary #' prev_preds <- forecast_secondary(prev, cases[101:.N][, value := primary]) #' plot(prev_preds, new_obs = cases, from = "2020-06-01") +#' +#' options(old_opts) #' } estimate_secondary <- function(reports, secondary = secondary_opts(), diff --git a/R/estimate_truncation.R b/R/estimate_truncation.R index e5b46e262..91c8a536f 100644 --- a/R/estimate_truncation.R +++ b/R/estimate_truncation.R @@ -50,7 +50,9 @@ #' @importFrom data.table copy .N as.data.table merge.data.table setDT setcolorder #' @examples #' # set number of cores to use +#' old_opts <- options() #' options(mc.cores = ifelse(interactive(), 4, 1)) +#' #' # get example case counts #' reported_cases <- example_confirmed[1:60] #' @@ -99,6 +101,8 @@ #' print(est$obs) #' # validation plot of observations vs estimates #' plot(est) +#' +#' options(old_opts) estimate_truncation <- function(obs, max_truncation = 10, model = NULL, CrIs = c(0.2, 0.5, 0.9), diff --git a/R/regional_epinow.R b/R/regional_epinow.R index a58d7d89c..83070c75b 100644 --- a/R/regional_epinow.R +++ b/R/regional_epinow.R @@ -40,6 +40,7 @@ #' #' \donttest{ #' # set number of cores to use +#' old_opts <- options() #' options(mc.cores = ifelse(interactive(), 4, 1)) #' #' # construct example distributions @@ -89,6 +90,8 @@ #' ), #' verbose = interactive() #' ) +#' +#' options(old_opts) #' } regional_epinow <- function(reported_cases, generation_time, diff --git a/R/simulate_infections.R b/R/simulate_infections.R index 9c6621742..53e9bb22b 100644 --- a/R/simulate_infections.R +++ b/R/simulate_infections.R @@ -32,7 +32,9 @@ #' @examples #' \donttest{ #' # set number of cores to use +#' old_opts <- options() #' options(mc.cores = ifelse(interactive(), 4, 1)) +#' #' # get example case counts #' reported_cases <- example_confirmed[1:50] #' @@ -76,6 +78,8 @@ #' R_samples <- R_samples[date >= "2020-04-01", value := 1.1] #' sims <- simulate_infections(est, R_samples) #' plot(sims) +#' +#' options(old_opts) #' } simulate_infections <- function(estimates, R = NULL, diff --git a/inst/dev/recover-synthetic.R b/inst/dev/recover-synthetic.R index f5e0500cc..878bb9ac0 100644 --- a/inst/dev/recover-synthetic.R +++ b/inst/dev/recover-synthetic.R @@ -2,6 +2,7 @@ library(EpiNow2) library(data.table) library(ggplot2) +old_opts <- options() options(mc.cores = 4) # set up example generation time @@ -253,3 +254,5 @@ idf %>% summarise_all(mean) %>% pivot_wider(names_from = "metric") %>% arrange(CRPS) + +options(old_opts) \ No newline at end of file diff --git a/man/epinow.Rd b/man/epinow.Rd index 1910a1cca..2d4eff625 100644 --- a/man/epinow.Rd +++ b/man/epinow.Rd @@ -117,6 +117,7 @@ example of using \code{epinow} to estimate Rt for Covid-19 in a country from the \examples{ \donttest{ # set number of cores to use +old_opts <- options() options(mc.cores = ifelse(interactive(), 4, 1)) # construct example distributions generation_time <- get_generation_time(disease = "SARS-CoV-2", source = "ganyani") @@ -145,6 +146,8 @@ plot(out) # summary of R estimates summary(out, type = "parameters", params = "R") + +options(old_opts) } } \seealso{ diff --git a/man/estimate_infections.Rd b/man/estimate_infections.Rd index d170e18d0..092c578b9 100644 --- a/man/estimate_infections.Rd +++ b/man/estimate_infections.Rd @@ -102,7 +102,9 @@ estimate Rt for Covid-19 in a country from the ECDC data source. \examples{ \donttest{ # set number of cores to use +old_opts <- options() options(mc.cores = ifelse(interactive(), 4, 1)) + # get example case counts reported_cases <- example_confirmed[1:60] @@ -249,6 +251,8 @@ rw <- estimate_infections(reported_cases, # random walk effects summary(rw, type = "parameters", params = "breakpoints") plot(rw) + +options(old_opts) } } \seealso{ diff --git a/man/estimate_secondary.Rd b/man/estimate_secondary.Rd index 184fc79d2..5aa9f29a4 100644 --- a/man/estimate_secondary.Rd +++ b/man/estimate_secondary.Rd @@ -74,7 +74,9 @@ for an application forecasting Covid-19 deaths in Germany and Poland. \examples{ \donttest{ # set number of cores to use +old_opts <- options() options(mc.cores = ifelse(interactive(), 4, 1)) + #' # load data.table for manipulation library(data.table) # load lubridate for dates @@ -167,5 +169,7 @@ plot(prev, primary = TRUE) # forecast future secondary cases from primary prev_preds <- forecast_secondary(prev, cases[101:.N][, value := primary]) plot(prev_preds, new_obs = cases, from = "2020-06-01") + +options(old_opts) } } diff --git a/man/estimate_truncation.Rd b/man/estimate_truncation.Rd index 837eeafc6..72d557988 100644 --- a/man/estimate_truncation.Rd +++ b/man/estimate_truncation.Rd @@ -73,7 +73,9 @@ This approach assumes that: } \examples{ # set number of cores to use +old_opts <- options() options(mc.cores = ifelse(interactive(), 4, 1)) + # get example case counts reported_cases <- example_confirmed[1:60] @@ -122,4 +124,6 @@ print(est$cmf) print(est$obs) # validation plot of observations vs estimates plot(est) + +options(old_opts) } diff --git a/man/regional_epinow.Rd b/man/regional_epinow.Rd index ccdf2ce2a..d26d6881e 100644 --- a/man/regional_epinow.Rd +++ b/man/regional_epinow.Rd @@ -115,6 +115,7 @@ progressr::handlers and enable it in batch by setting \code{R_PROGRESSR_ENABLE=T \donttest{ # set number of cores to use +old_opts <- options() options(mc.cores = ifelse(interactive(), 4, 1)) # construct example distributions @@ -164,6 +165,8 @@ region_rt <- regional_epinow( ), verbose = interactive() ) + +options(old_opts) } } \seealso{ diff --git a/man/simulate_infections.Rd b/man/simulate_infections.Rd index 5f36becf8..096bf826f 100644 --- a/man/simulate_infections.Rd +++ b/man/simulate_infections.Rd @@ -49,7 +49,9 @@ Simulations can be run in parallel using \code{future::plan}. \examples{ \donttest{ # set number of cores to use +old_opts <- options() options(mc.cores = ifelse(interactive(), 4, 1)) + # get example case counts reported_cases <- example_confirmed[1:50] @@ -93,5 +95,7 @@ R_samples <- R_samples[, .(date, sample, value)][sample <= 1000][date <= "2020-0 R_samples <- R_samples[date >= "2020-04-01", value := 1.1] sims <- simulate_infections(est, R_samples) plot(sims) + +options(old_opts) } } diff --git a/tests/testthat/test-estimate_truncation.R b/tests/testthat/test-estimate_truncation.R index 205dcbf39..b7dd31f34 100644 --- a/tests/testthat/test-estimate_truncation.R +++ b/tests/testthat/test-estimate_truncation.R @@ -3,7 +3,9 @@ skip_on_cran() futile.logger::flog.threshold("FATAL") # set number of cores to use + options(old_opts) options(mc.cores = ifelse(interactive(), 4, 1)) + # get example case counts reported_cases <- example_confirmed[1:60] @@ -55,3 +57,5 @@ test_that("estimate_truncation can return values from simulated data and plot ) expect_error(plot(est), NA) }) + +options(old_opts) \ No newline at end of file