Skip to content

Commit

Permalink
add option resetting as requested by CRAN
Browse files Browse the repository at this point in the history
  • Loading branch information
seabbs committed Oct 20, 2022
1 parent 8e95120 commit d3ec787
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 0 deletions.
3 changes: 3 additions & 0 deletions R/epinow.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -54,6 +55,8 @@
#'
#' # summary of R estimates
#' summary(out, type = "parameters", params = "R")
#'
#' options(old_opts)
#' }
epinow <- function(reported_cases,
generation_time = NULL,
Expand Down
4 changes: 4 additions & 0 deletions R/estimate_infections.R
Original file line number Diff line number Diff line change
Expand Up @@ -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]
#'
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions R/estimate_secondary.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand Down
4 changes: 4 additions & 0 deletions R/estimate_truncation.R
Original file line number Diff line number Diff line change
Expand Up @@ -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]
#'
Expand Down Expand Up @@ -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),
Expand Down
3 changes: 3 additions & 0 deletions R/regional_epinow.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#'
#' \donttest{
#' # set number of cores to use
#' old_opts <- options()
#' options(mc.cores = ifelse(interactive(), 4, 1))
#'
#' # construct example distributions
Expand Down Expand Up @@ -89,6 +90,8 @@
#' ),
#' verbose = interactive()
#' )
#'
#' options(old_opts)
#' }
regional_epinow <- function(reported_cases,
generation_time,
Expand Down
4 changes: 4 additions & 0 deletions R/simulate_infections.R
Original file line number Diff line number Diff line change
Expand Up @@ -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]
#'
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions inst/dev/recover-synthetic.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ library(EpiNow2)
library(data.table)
library(ggplot2)

old_opts <- options()
options(mc.cores = 4)

# set up example generation time
Expand Down Expand Up @@ -253,3 +254,5 @@ idf %>%
summarise_all(mean) %>%
pivot_wider(names_from = "metric") %>%
arrange(CRPS)

options(old_opts)
3 changes: 3 additions & 0 deletions man/epinow.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions man/estimate_infections.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions man/estimate_secondary.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions man/estimate_truncation.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/regional_epinow.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions man/simulate_infections.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions tests/testthat/test-estimate_truncation.R
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -55,3 +57,5 @@ test_that("estimate_truncation can return values from simulated data and plot
)
expect_error(plot(est), NA)
})

options(old_opts)

0 comments on commit d3ec787

Please sign in to comment.