Skip to content

Commit

Permalink
add case data source
Browse files Browse the repository at this point in the history
  • Loading branch information
sbfnk committed Dec 11, 2023
1 parent 44a6117 commit 1330221
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions code/auto_download/cases-deaths/get-ecdc.r
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ library("purrr")
library("tidyr")
library("dplyr")
library("vroom")
library("tibble")
library("ISOweek")

get_ecdc <- function(earliest_date = lubridate::today() - 7,
Expand Down Expand Up @@ -61,16 +62,28 @@ get_ecdc <- function(earliest_date = lubridate::today() - 7,
dplyr::select(
location_name, location, target_variable, date, value, source
)
file_name <- paste0("covid-cases-deaths_", file_date, ".csv")
vroom::vroom_write(df, file.path(local_path, file_name), delim = ",")
return(df)
} else {
return(NULL)
}
}

## save snapshots
snapshots <- purrr::map(process_files, dl_snapshot)
snapshots <- tibble(
file_name = process_files,
data = purrr::map(process_files, dl_snapshot)
) |>
dplyr::mutate(
file_date = as.Date(
sub("^.*([0-9]{4}-[0-9]{2}-[0-9]{2}).*$", "\\1", file_name)
),
file = file.path(
local_path, paste0("covid-cases-deaths_", file_date, ".csv")
)
) |>
dplyr::group_by(file) |>
dplyr::summarise(x = list(bind_rows(data)), .groups = "keep") |>
purrr::pmap(vroom::vroom_write, delim = ", ")

return(snapshots)
}

0 comments on commit 1330221

Please sign in to comment.