From c86ac10fdef6323f7830d2bd9a4b6322f9cf45bd Mon Sep 17 00:00:00 2001 From: Dmitry Shemetov Date: Wed, 2 Oct 2024 18:57:16 -0700 Subject: [PATCH 1/4] refactor: remove Suggests dependence on covidcast * just download the state data file, don't import covidcast * covidcast depends on sf which is tough to install --- DESCRIPTION | 1 - data-raw/case_death_rate_subset.R | 7 ++----- data-raw/state_census.R | 7 +++++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index d3369cf23..0834489d6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -49,7 +49,6 @@ Imports: vctrs, workflows (>= 1.0.0) Suggests: - covidcast, data.table, epidatr (>= 1.0.0), fs, diff --git a/data-raw/case_death_rate_subset.R b/data-raw/case_death_rate_subset.R index 4bf416dbf..4fa3e64a7 100644 --- a/data-raw/case_death_rate_subset.R +++ b/data-raw/case_death_rate_subset.R @@ -1,9 +1,8 @@ library(tidyverse) -library(covidcast) library(epidatr) library(epiprocess) -x <- covidcast( +x <- pub_covidcast( data_source = "jhu-csse", signals = "confirmed_7dav_incidence_prop", time_type = "day", @@ -11,10 +10,9 @@ x <- covidcast( time_values = epirange(20201231, 20211231), geo_values = "*" ) %>% - fetch() %>% select(geo_value, time_value, case_rate = value) -y <- covidcast( +y <- pub_covidcast( data_source = "jhu-csse", signals = "deaths_7dav_incidence_prop", time_type = "day", @@ -22,7 +20,6 @@ y <- covidcast( time_values = epirange(20201231, 20211231), geo_values = "*" ) %>% - fetch() %>% select(geo_value, time_value, death_rate = value) case_death_rate_subset <- x %>% diff --git a/data-raw/state_census.R b/data-raw/state_census.R index 22dde5a41..df9b1b3db 100644 --- a/data-raw/state_census.R +++ b/data-raw/state_census.R @@ -1,11 +1,14 @@ library(dplyr) library(tidyr) -state_census <- covidcast::state_census %>% +remote_file <- "https://github.com/cmu-delphi/covidcast/raw/refs/heads/main/R-packages/covidcast/data/state_census.rda" +download.file(remote_file, "state_census.rda") +load("state_census.rda") +state_census <- state_census %>% select(STATE, NAME, POPESTIMATE2019, ABBR) %>% rename(abbr = ABBR, name = NAME, pop = POPESTIMATE2019, fips = STATE) %>% mutate(abbr = tolower(abbr)) %>% as_tibble() - +file.remove("state_census.rda") usethis::use_data(state_census, overwrite = TRUE) From 65448b5969f4a7d8fc3c168041d8878d4c1aa513 Mon Sep 17 00:00:00 2001 From: Dmitry Shemetov Date: Wed, 2 Oct 2024 19:17:46 -0700 Subject: [PATCH 2/4] fix: simplify --- data-raw/state_census.R | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/data-raw/state_census.R b/data-raw/state_census.R index df9b1b3db..9cd495ce9 100644 --- a/data-raw/state_census.R +++ b/data-raw/state_census.R @@ -1,14 +1,10 @@ library(dplyr) library(tidyr) -remote_file <- "https://github.com/cmu-delphi/covidcast/raw/refs/heads/main/R-packages/covidcast/data/state_census.rda" -download.file(remote_file, "state_census.rda") -load("state_census.rda") -state_census <- state_census %>% +state_census <- read_csv("https://github.com/cmu-delphi/covidcast/raw/c89e4d295550ba1540d64d2cc991badf63ad04e5/Python-packages/covidcast-py/covidcast/geo_mappings/state_census.csv") %>% select(STATE, NAME, POPESTIMATE2019, ABBR) %>% rename(abbr = ABBR, name = NAME, pop = POPESTIMATE2019, fips = STATE) %>% mutate(abbr = tolower(abbr)) %>% as_tibble() -file.remove("state_census.rda") usethis::use_data(state_census, overwrite = TRUE) From 6805d98ce2e6fd2123c59005e795da2852940a72 Mon Sep 17 00:00:00 2001 From: Dmitry Shemetov Date: Wed, 2 Oct 2024 19:32:08 -0700 Subject: [PATCH 3/4] fix: some borked tests --- tests/testthat/_snaps/population_scaling.md | 16 ++++++++++++++++ tests/testthat/_snaps/step_epi_slide.md | 4 ++-- tests/testthat/test-grf_quantiles.R | 2 +- tests/testthat/test-snapshots.R | 6 +++--- 4 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 tests/testthat/_snaps/population_scaling.md diff --git a/tests/testthat/_snaps/population_scaling.md b/tests/testthat/_snaps/population_scaling.md new file mode 100644 index 000000000..9263e8e1e --- /dev/null +++ b/tests/testthat/_snaps/population_scaling.md @@ -0,0 +1,16 @@ +# expect error if `by` selector does not match + + Code + wf <- epi_workflow(r, parsnip::linear_reg()) %>% fit(jhu) %>% add_frosting(f) + Condition + Error in `hardhat::validate_column_names()`: + ! The following required columns are missing: 'a'. + +--- + + Code + forecast(wf) + Condition + Error in `hardhat::validate_column_names()`: + ! The following required columns are missing: 'nothere'. + diff --git a/tests/testthat/_snaps/step_epi_slide.md b/tests/testthat/_snaps/step_epi_slide.md index a4b9d64c8..7493a7fea 100644 --- a/tests/testthat/_snaps/step_epi_slide.md +++ b/tests/testthat/_snaps/step_epi_slide.md @@ -12,7 +12,7 @@ r %>% step_epi_slide(value, .f = mean, .window_size = c(3L, 6L)) Condition Error in `epiprocess:::validate_slide_window_arg()`: - ! Slide function expected `.window_size` to be a non-null, scalar integer >= 1. + ! Slide function expected `.window_size` to be a length-1 difftime with units in days or non-negative integer or Inf. --- @@ -60,7 +60,7 @@ r %>% step_epi_slide(value, .f = mean, .window_size = 1.5) Condition Error in `epiprocess:::validate_slide_window_arg()`: - ! Slide function expected `.window_size` to be a difftime with units in days or non-negative integer or Inf. + ! Slide function expected `.window_size` to be a length-1 difftime with units in days or non-negative integer or Inf. --- diff --git a/tests/testthat/test-grf_quantiles.R b/tests/testthat/test-grf_quantiles.R index 2570c247d..5bbaed01f 100644 --- a/tests/testthat/test-grf_quantiles.R +++ b/tests/testthat/test-grf_quantiles.R @@ -10,7 +10,7 @@ test_that("quantile_rand_forest defaults work", { expect_silent(out <- fit(spec, formula = y ~ x + z, data = tib)) pars <- parsnip::extract_fit_engine(out) manual <- quantile_forest(as.matrix(tib[, 2:3]), tib$y, quantiles = c(0.1, 0.5, 0.9)) - expect_identical(pars$quantiles.orig, manual$quantiles) + expect_identical(pars$quantiles.orig, manual$quantiles.orig) expect_identical(pars$`_num_trees`, manual$`_num_trees`) fseed <- 12345 diff --git a/tests/testthat/test-snapshots.R b/tests/testthat/test-snapshots.R index da8635ae0..5af492378 100644 --- a/tests/testthat/test-snapshots.R +++ b/tests/testthat/test-snapshots.R @@ -117,7 +117,7 @@ test_that("arx_forecaster output format snapshots", { jhu, "death_rate", c("case_rate", "death_rate") ) - expect_equal(as.Date(out1$metadata$forecast_created), Sys.Date()) + expect_equal(as.Date(format(out1$metadata$forecast_created, "%Y-%m-%d")), Sys.Date()) out1$metadata$forecast_created <- as.Date("0999-01-01") expect_snapshot(out1) out2 <- arx_forecaster(jhu, "case_rate", @@ -129,7 +129,7 @@ test_that("arx_forecaster output format snapshots", { forecast_date = as.Date("2022-01-03") ) ) - expect_equal(as.Date(out2$metadata$forecast_created), Sys.Date()) + expect_equal(as.Date(format(out2$metadata$forecast_created, "%Y-%m-%d")), Sys.Date()) out2$metadata$forecast_created <- as.Date("0999-01-01") expect_snapshot(out2) out3 <- arx_forecaster(jhu, "death_rate", @@ -140,7 +140,7 @@ test_that("arx_forecaster output format snapshots", { forecast_date = as.Date("2022-01-03") ) ) - expect_equal(as.Date(out3$metadata$forecast_created), Sys.Date()) + expect_equal(as.Date(format(out3$metadata$forecast_created, "%Y-%m-%d")), Sys.Date()) out3$metadata$forecast_created <- as.Date("0999-01-01") expect_snapshot(out3) }) From 57df54c2fa5903ca3c9aae9b6cf37a3c8a367364 Mon Sep 17 00:00:00 2001 From: Dmitry Shemetov Date: Wed, 2 Oct 2024 20:00:27 -0700 Subject: [PATCH 4/4] fix: add readr --- DESCRIPTION | 1 + data-raw/state_census.R | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 0834489d6..2bd433f6f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -60,6 +60,7 @@ Suggests: quantreg, ranger, RcppRoll, + readr, rmarkdown, smoothqr, testthat (>= 3.0.0), diff --git a/data-raw/state_census.R b/data-raw/state_census.R index 9cd495ce9..cfa74d38b 100644 --- a/data-raw/state_census.R +++ b/data-raw/state_census.R @@ -1,7 +1,7 @@ library(dplyr) library(tidyr) -state_census <- read_csv("https://github.com/cmu-delphi/covidcast/raw/c89e4d295550ba1540d64d2cc991badf63ad04e5/Python-packages/covidcast-py/covidcast/geo_mappings/state_census.csv") %>% +state_census <- readr::read_csv("https://github.com/cmu-delphi/covidcast/raw/c89e4d295550ba1540d64d2cc991badf63ad04e5/Python-packages/covidcast-py/covidcast/geo_mappings/state_census.csv") %>% # nolint: line_length_linter select(STATE, NAME, POPESTIMATE2019, ABBR) %>% rename(abbr = ABBR, name = NAME, pop = POPESTIMATE2019, fips = STATE) %>% mutate(abbr = tolower(abbr)) %>%