Skip to content

Commit 6a9fcc6

Browse files
committed
use local file to update NSSP data
1 parent eaee58f commit 6a9fcc6

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

R/update_hub_target_data.R

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ nssp_col_names <- list(
2424
#' is "2024-11-09".
2525
#' @param legacy_file Logical. Whether to write legacy
2626
#' CSV output (default: FALSE).
27+
#' @param nssp_update_local Logical. Whether to update NSSP
28+
#' data from local file `auxiliary-data/latest.csv`
29+
#' (default: FALSE).
2730
#'
2831
#' @return Writes `time-series.parquet` and optionally
2932
#' legacy CSV target data files to the target-data
@@ -35,7 +38,8 @@ update_hub_target_data <- function(
3538
as_of = lubridate::today(),
3639
nhsn_first_weekending_date = lubridate::as_date("2024-11-09"),
3740
included_locations = hubhelpr::included_locations,
38-
legacy_file = FALSE
41+
legacy_file = FALSE,
42+
nssp_update_local = FALSE
3943
) {
4044
if (!disease %in% c("covid", "rsv")) {
4145
stop("'disease' must be either 'covid' or 'rsv'")
@@ -90,11 +94,31 @@ update_hub_target_data <- function(
9094
)
9195
}
9296

93-
hubverse_format_nssp_data <- forecasttools::pull_data_cdc_gov_dataset(
94-
dataset = "nssp_prop_ed_visits",
95-
columns = c(nssp_col_name, "geography"),
96-
locations = "All"
97-
) |>
97+
if (nssp_update_local) {
98+
raw_nssp_data <- forecasttools::read_tabular(
99+
fs::path(
100+
base_hub_path,
101+
"auxiliary-data",
102+
"nssp-raw-data",
103+
"latest",
104+
ext = "csv"
105+
)
106+
) |>
107+
dplyr::filter(county == "All") |>
108+
dplyr::select(
109+
week_end,
110+
geography,
111+
dplyr::all_of(nssp_col_name)
112+
)
113+
} else {
114+
raw_nssp_data <- forecasttools::pull_data_cdc_gov_dataset(
115+
dataset = "nssp_prop_ed_visits",
116+
columns = c(nssp_col_name, "geography"),
117+
locations = "All"
118+
)
119+
}
120+
121+
hubverse_format_nssp_data <- raw_nssp_data |>
98122
dplyr::mutate(
99123
date = lubridate::as_date(.data$week_end),
100124
observation = as.numeric(.data[[nssp_col_name]]) / 100,

man/update_hub_target_data.Rd

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)