From bb12c41ec4753b9c718dd0abbb6609f54e0d5b84 Mon Sep 17 00:00:00 2001 From: Zachary Susswein Date: Sat, 31 Aug 2024 14:11:32 +0000 Subject: [PATCH] Add parameter skipping --- R/parameters.R | 2 + tests/testthat/test-parameters.R | 65 +++++++++++++++++++++++++++++++- 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/R/parameters.R b/R/parameters.R index 2aef6ca8..2671f74f 100644 --- a/R/parameters.R +++ b/R/parameters.R @@ -23,6 +23,7 @@ read_parameters <- function( cli::cli_alert_warning( "No delay interval path specified. Using a delay of 0 days" ) + delay_interval <- NA } if (path_is_specified(right_truncation_path)) { @@ -37,6 +38,7 @@ read_parameters <- function( cli::cli_alert_warning( "No right truncation path specified. Not adjusting for right truncation." ) + right_truncation <- NA } parameters <- list( diff --git a/tests/testthat/test-parameters.R b/tests/testthat/test-parameters.R index 00b07ab4..650c4abf 100644 --- a/tests/testthat/test-parameters.R +++ b/tests/testthat/test-parameters.R @@ -44,7 +44,70 @@ test_that("Can read all params on happy path", { }) - expect_equal(actual, c(rep(list(c(0.8, 0.2)), 3))) + expect_equal( + actual, + list( + generation_interval = expected, + delay_interval = expected, + right_truncation = expected + ) + ) +}) + +test_that("Can skip params on happy path", { + expected <- c(0.8, 0.2) + start_date <- as.Date("2023-01-01") + disease <- "COVID-19" + + withr::with_tempdir({ + write_sample_parameters_file( + value = expected, + parameter = "generation_interval", + path = "generation_interval.parquet", + disease = disease, + state = NA, + start_date = start_date, + end_date = NA + ) + write_sample_parameters_file( + value = expected, + parameter = "delay", + path = "delay_interval.parquet", + disease = disease, + state = NA, + start_date = start_date, + end_date = NA + ) + write_sample_parameters_file( + value = expected, + parameter = "right_truncation", + path = "right_truncation.parquet", + disease = disease, + state = "test", + start_date = start_date, + end_date = NA + ) + + + actual <- read_parameters( + generation_interval_path = "generation_interval.parquet", + delay_interval_path = NULL, + right_truncation_path = NULL, + disease = "COVID-19", + as_of_date = start_date + 1, + state = "test" + ) + }) + + + expect_equal( + actual, + list( + generation_interval = expected, + delay_interval = NA, + right_truncation = NA + ) + ) }) test_that("Can read right-truncation on happy path", {