diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index cad87c716..e75af694e 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -65,7 +65,8 @@ jobs: stan-dev/cmdstanr testthat - - name: Install cmdstan + - if: startsWith(matrix.os, 'windows') != true + name: Install cmdstan uses: epinowcast/actions/install-cmdstan@v1 with: cmdstan-version: 'latest' diff --git a/tests/testthat/test-epinow.R b/tests/testthat/test-epinow.R index fe481b909..6c507564e 100644 --- a/tests/testthat/test-epinow.R +++ b/tests/testthat/test-epinow.R @@ -40,6 +40,7 @@ test_that("epinow produces expected output when run with default settings", { test_that("epinow produces expected output when run with the cmdstanr backend", { + skip_on_os("windows") output <- capture.output(suppressMessages(suppressWarnings( out <- epinow( reported_cases = reported_cases, diff --git a/tests/testthat/test-estimate_secondary.R b/tests/testthat/test-estimate_secondary.R index ad9a586b8..5485f309b 100644 --- a/tests/testthat/test-estimate_secondary.R +++ b/tests/testthat/test-estimate_secondary.R @@ -5,14 +5,16 @@ skip_on_cran() # make some example secondary incidence data cases <- example_confirmed cases <- as.data.table(cases)[, primary := confirm] + +inc_cases <- copy(cases) # Assume that only 40 percent of cases are reported -cases[, scaling := 0.4] +inc_cases[, scaling := 0.4] # Parameters of the assumed log normal delay distribution -cases[, meanlog := 1.8][, sdlog := 0.5] +inc_cases[, meanlog := 1.8][, sdlog := 0.5] # Simulate secondary cases -cases <- simulate_secondary(cases, type = "incidence") -cases[ +inc_cases <- simulate_secondary(inc_cases, type = "incidence") +inc_cases[ , c("confirm", "scaling", "meanlog", "sdlog", "index", "scaled", "conv") := NULL @@ -20,18 +22,11 @@ cases[ # # fit model to example data specifying a weak prior for fraction reported # with a secondary case -inc <- estimate_secondary(cases[1:60], +inc <- estimate_secondary(inc_cases[1:60], obs = obs_opts(scale = list(mean = 0.2, sd = 0.2), week_effect = FALSE), verbose = FALSE ) -output <- capture.output(suppressMessages(suppressWarnings( - inc_cmdstanr <- estimate_secondary(cases[1:60], - obs = obs_opts(scale = list(mean = 0.2, sd = 0.2), week_effect = FALSE), - verbose = FALSE, stan = stan_opts(backend = "cmdstanr") - ) -))) - # extract posterior variables of interest params <- c( "meanlog" = "delay_mean[1]", "sdlog" = "delay_sd[1]", @@ -39,23 +34,21 @@ params <- c( ) inc_posterior <- inc$posterior[variable %in% params] -inc_posterior_cmdstanr <- inc_cmdstanr$posterior[variable %in% params] #### Prevalence data example #### # make some example prevalence data -cases <- example_confirmed -cases <- as.data.table(cases)[, primary := confirm] +prev_cases <- copy(cases) # Assume that only 30 percent of cases are reported -cases[, scaling := 0.3] +prev_cases[, scaling := 0.3] # Parameters of the assumed log normal delay distribution -cases[, meanlog := 1.6][, sdlog := 0.8] +prev_cases[, meanlog := 1.6][, sdlog := 0.8] # Simulate secondary cases -cases <- simulate_secondary(cases, type = "prevalence") +prev_cases <- simulate_secondary(prev_cases, type = "prevalence") # fit model to example prevalence data -prev <- estimate_secondary(cases[1:100], +prev <- estimate_secondary(prev_cases[1:100], secondary = secondary_opts(type = "prevalence"), obs = obs_opts( week_effect = FALSE, @@ -102,6 +95,14 @@ test_that("estimate_secondary can recover simulated parameters", { test_that("estimate_secondary can recover simulated parameters with the cmdstanr backend", { + skip_on_os("windows") + output <- capture.output(suppressMessages(suppressWarnings( + inc_cmdstanr <- estimate_secondary(inc_cases[1:60], + obs = obs_opts(scale = list(mean = 0.2, sd = 0.2), week_effect = FALSE), + verbose = FALSE, stan = stan_opts(backend = "cmdstanr") + ) + ))) + inc_posterior_cmdstanr <- inc_cmdstanr$posterior[variable %in% params] expect_equal( inc_posterior_cmdstanr[, mean], c(1.8, 0.5, 0.4), tolerance = 0.1 @@ -114,17 +115,20 @@ test_that("estimate_secondary can recover simulated parameters with the test_that("forecast_secondary can return values from simulated data and plot them", { - inc_preds <- forecast_secondary(inc, cases[seq(61, .N)][, value := primary]) + inc_preds <- forecast_secondary( + inc, inc_cases[seq(61, .N)][, value := primary] + ) expect_equal(names(inc_preds), c("samples", "forecast", "predictions")) # validation plot of observations vs estimates - expect_error(plot(inc_preds, new_obs = cases, from = "2020-05-01"), NA) + expect_error(plot(inc_preds, new_obs = inc_cases, from = "2020-05-01"), NA) }) test_that("forecast_secondary can return values from simulated data when using the cmdstanr backend", { + skip_on_os("windows") capture.output(suppressMessages(suppressWarnings( inc_preds <- forecast_secondary( - inc_cmdstanr, cases[seq(61, .N)][, value := primary], backend = "cmdstanr" + inc, inc_cases[seq(61, .N)][, value := primary], backend = "cmdstanr" ) ))) expect_equal(names(inc_preds), c("samples", "forecast", "predictions")) @@ -135,7 +139,7 @@ test_that("estimate_secondary works with weigh_delay_priors = TRUE", { mean = 2.5, mean_sd = 0.5, sd = 0.47, sd_sd = 0.25, max = 30 ) inc_weigh <- estimate_secondary( - cases[1:60], delays = delay_opts(delays), + inc_cases[1:60], delays = delay_opts(delays), obs = obs_opts(scale = list(mean = 0.2, sd = 0.2), week_effect = FALSE), weigh_delay_priors = TRUE, verbose = FALSE ) diff --git a/tests/testthat/test-estimate_truncation.R b/tests/testthat/test-estimate_truncation.R index ae72d82f4..c1fd03e8e 100644 --- a/tests/testthat/test-estimate_truncation.R +++ b/tests/testthat/test-estimate_truncation.R @@ -57,6 +57,7 @@ test_that("estimate_truncation can return values from simulated data and plot test_that("estimate_truncation can return values from simulated data with the cmdstanr backend", { # fit model to example data + skip_on_os("windows") output <- capture.output(suppressMessages(suppressWarnings( est <- estimate_truncation(example_data, verbose = FALSE, chains = 2, iter = 1000, warmup = 250, diff --git a/tests/testthat/test-simulate_infections.R b/tests/testthat/test-simulate_infections.R index 951ddce6b..d63344a7b 100644 --- a/tests/testthat/test-simulate_infections.R +++ b/tests/testthat/test-simulate_infections.R @@ -22,6 +22,7 @@ test_that("simulate_infections works to simulate a passed in estimate_infections test_that("simulate_infections works to simulate a passed in estimate_infections object when using the cmdstanr backend", { + skip_on_os("windows") output <- capture.output(suppressMessages(suppressWarnings( sims <- simulate_infections(out, backend = "cmdstanr") )))