From 13302213075c95cb4414d2582e68bc57fe87cbb6 Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Mon, 11 Dec 2023 08:51:00 +0000 Subject: [PATCH] add case data source --- code/auto_download/cases-deaths/get-ecdc.r | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/code/auto_download/cases-deaths/get-ecdc.r b/code/auto_download/cases-deaths/get-ecdc.r index d0c251a13a..184f299980 100644 --- a/code/auto_download/cases-deaths/get-ecdc.r +++ b/code/auto_download/cases-deaths/get-ecdc.r @@ -5,6 +5,7 @@ library("purrr") library("tidyr") library("dplyr") library("vroom") +library("tibble") library("ISOweek") get_ecdc <- function(earliest_date = lubridate::today() - 7, @@ -61,8 +62,6 @@ 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) @@ -70,7 +69,21 @@ get_ecdc <- function(earliest_date = lubridate::today() - 7, } ## 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) }