Make historical RDS data optional when running preprocessing - #294
Make historical RDS data optional when running preprocessing #294chadhunt2 wants to merge 7 commits into
Conversation
mcuadera
left a comment
There was a problem hiding this comment.
We're still requiring the use of files located in "core_files_to_combine." Please see my comments.
| cli::cli_alert_warning(paste0( | ||
| "Please request the following file(s) from the SIR team", | ||
| "and move them into: ", core_files_folder_path | ||
| )) | ||
| for (file in missing_static_files) { | ||
| cli::cli_alert_info(paste0(file, "\n")) | ||
| } |
There was a problem hiding this comment.
This should be removed since we're making the historical datasets optional
| cli::cli_process_start("Generating combined AFP dataset", | ||
| msg_done = "Generated combined AFP dataset" | ||
| ) | ||
|
|
||
| # Find all AFP files in Core_Ready_Files and core_files_to_combine | ||
| afp_files_main <- dplyr::tibble("name" = tidypolis_io( | ||
| io = "list", | ||
| file_path = paste0(polis_data_folder, "/", output_folder_name), | ||
| full_names = TRUE | ||
| )) |> | ||
| dplyr::filter(grepl(paste0("^.*(afp_linelist).*(\\", output_format, ")$"), name)) |> | ||
| dplyr::pull(name) | ||
|
|
||
| afp_files_combine <- dplyr::tibble("name" = tidypolis_io( | ||
| io = "list", | ||
| file_path = paste0(polis_data_folder, "/core_files_to_combine"), | ||
| full_names = TRUE | ||
| )) |> | ||
| dplyr::filter(grepl("^.*(afp_linelist).*(.rds)$", name)) |> | ||
| dplyr::pull(name) | ||
|
|
||
| # Combine AFP files | ||
| if (length(afp_files_combine) > 0) { | ||
| invisible(capture.output( | ||
| afp_to_combine <- purrr::map_df(afp_files_combine, ~ tidypolis_io( | ||
| io = "read", | ||
| file_path = .x | ||
| )) |> | ||
| dplyr::mutate( | ||
| stool1tostool2 = as.numeric(stool1tostool2), | ||
| datenotificationtohq = lubridate::parse_date_time( | ||
| datenotificationtohq, | ||
| c("dmY", "bY", "Ymd", "%Y-%m-%d %H:%M:%S") | ||
| ) | ||
| ) | ||
| )) | ||
|
|
||
| invisible(capture.output( | ||
| afp_new <- purrr::map_df( | ||
| afp_files_main, | ||
| ~ tidypolis_io(io = "read", file_path = .x) | ||
| ) | ||
| )) | ||
|
|
||
| afp_combined <- dplyr::bind_rows(afp_new, afp_to_combine) | ||
|
|
||
| # Export combined AFP dataset | ||
| invisible(capture.output( | ||
| tidypolis_io( | ||
| obj = afp_combined, | ||
| io = "write", | ||
| file_path = paste0( | ||
| polis_data_folder, | ||
| "/", output_folder_name, "/", | ||
| "afp_linelist_", | ||
| min(afp_combined$dateonset, na.rm = TRUE), | ||
| "_", | ||
| max(afp_combined$dateonset, na.rm = TRUE), | ||
| output_format | ||
| ) | ||
| ) | ||
| )) |
There was a problem hiding this comment.
We're still using the historical datasets to get an AFP linelist. We want to make this non-required
| cli::cli_process_start("Generating combined Other Surveillance dataset", | ||
| msg_done = "Generated combined Other Surveillance dataset" | ||
| ) | ||
|
|
||
| # Find all other surveillance files in Core_Ready_Files and core_files_to_combine | ||
| other_files_main <- dplyr::tibble("name" = tidypolis_io( | ||
| io = "list", | ||
| file_path = paste0(polis_data_folder, "/", output_folder_name), | ||
| full_names = TRUE | ||
| )) |> | ||
| dplyr::filter(grepl(paste0("^.*(other_surveillance).*(\\", output_format, ")$"), name)) |> | ||
| dplyr::pull(name) | ||
|
|
||
| other_files_combine <- dplyr::tibble("name" = tidypolis_io( | ||
| io = "list", | ||
| file_path = paste0(polis_data_folder, "/core_files_to_combine"), | ||
| full_names = TRUE | ||
| )) |> | ||
| dplyr::filter(grepl("^.*(other_surveillance).*(.rds)$", name)) |> | ||
| dplyr::pull(name) | ||
|
|
||
| # Combine other surveillance files | ||
| if (length(other_files_combine) > 0) { | ||
| invisible(capture.output( | ||
| other_to_combine <- purrr::map_df(other_files_combine, ~ tidypolis_io( | ||
| io = "read", | ||
| file_path = .x | ||
| )) | ||
| )) | ||
|
|
||
| other_to_combine <- other_to_combine |> | ||
| dplyr::mutate( | ||
| stool1tostool2 = as.numeric(stool1tostool2), | ||
| datenotificationtohq = lubridate::parse_date_time( | ||
| datenotificationtohq, | ||
| c("dmY", "bY", "Ymd", "%Y-%m-%d %H:%M:%S") | ||
| ) | ||
| ) | ||
|
|
||
| invisible(capture.output( | ||
| other_new <- purrr::map_df( | ||
| other_files_main, | ||
| ~ tidypolis_io(io = "read", file_path = .x) | ||
| ) | ||
| )) | ||
|
|
||
| other_combined <- dplyr::bind_rows(other_new, other_to_combine) | ||
|
|
||
| # Export combined other surveillance dataset | ||
| invisible(capture.output( | ||
| tidypolis_io( | ||
| obj = other_combined, | ||
| io = "write", | ||
| file_path = paste0( | ||
| polis_data_folder, | ||
| "/", output_folder_name, | ||
| "/other_surveillance_type_linelist_", | ||
| min(other_combined$yronset, na.rm = TRUE), | ||
| "_", | ||
| max(other_combined$yronset, na.rm = TRUE), | ||
| output_format | ||
| ) | ||
| ) | ||
| )) | ||
|
|
||
| cli::cli_process_done() | ||
| } |
There was a problem hiding this comment.
we're still using the historical dataset to make the "other" linelist
| #' @returns `tibble` sia.clean.01 All historical SIA data | ||
| #' @keywords internal | ||
| #' | ||
| s3_sia_combine_historical_data <- function(sia.new, polis_data_folder) { |
There was a problem hiding this comment.
this whole function shouldn't be needed anymore, and wherever it's used. however, please double check that sia.06 contains sia data in 2000-2019. Our primarily goal is to see whether these "historical" datasets are something we need to run preprocessing properly.
Updated init.R to give a warning if historical data files are not present instead of aborting.