R/load_nbs_new.R

Defines functions load_nbs_new

Documented in load_nbs_new

#' Load Latest Reported NBS Data
#'
#' `load_nbs_new()` loads the latest fully processed NBS data. It relies on a
#' separate job to update the report date file nightly, and it uses these report
#' dates to determine new cases.
#'
#' This means that `load_nbs_new()` will not immediately load new data once the
#' day's NBS file has been downloaded; the report date job must be run first.
#' This is currently by design, so that the function remains consistent
#' throughout a given day.
#'
#' @return A `tibble` containing NBS investigations file data, filtered by date
#'
#' @export
load_nbs_new <- function() {

  # Get last reported observations
  new_reports <- load_report_date() %>%
    dplyr::as_tibble() %>%
    dplyr::filter(.data$report_date == max(.data$report_date, na.rm = TRUE)) %>%
    dplyr::pull("inv_local_id")

  # Load ALTREP of NBS data file
  nbs_data <- path_inv() %>% read_file_delim() %>% janitor::clean_names()

  # Filter out old observations
  dplyr::inner_join(nbs_data, new_reports, by = "inv_local_id")
}
jesse-smith/covidCFR documentation built on Jan. 21, 2021, 2:32 a.m.