R/hfr_import.R

Defines functions hfr_import

Documented in hfr_import

#' Import template sheet(s)
#'
#' Read in a standard HFR submission, binding all tabs into one. Note that all
#' tabs must be in the same template format - all long, wide, or wide-limited.
#'
#' @param filepath filepath to submitted template
#'
#' @export
#'
#' @examples
#' \dontrun{
#' #identify whether template is long or wide
#'   filepath <- "~/HFR/HFR_FY23_Oct_Moldova_20221015.xlsx"
#'   df_hfr <- hfr_import(filepath) }

hfr_import <- function(filepath){

  df <- filepath %>%
    readxl::excel_sheets() %>%
    stringr::str_subset("HFR") %>%
    purrr::map_dfr(.f = ~ readxl::read_excel(filepath, sheet = .x, skip = 1, col_types = "text"))

  #replaces the old name for mech_code
  if("mechanismid" %in% names(df))
    df <- dplyr::rename(df, mech_code = mechanismid)

  return(df)

}
USAID-OHA-SI/Wavelength documentation built on March 24, 2023, 10:07 a.m.