R/hfr_munge_string.R

Defines functions hfr_munge_string

Documented in hfr_munge_string

#' Standardized Text
#'
#' Clean up/standardize string text for indicators and disaggregates
#'
#' @param df HFR data frame imported via `hfr_import()`
#'
#' @export
#'

hfr_munge_string <- function(df){

  df <- df %>%
    dplyr::mutate(indicator = toupper(indicator),
                  indicator = dplyr::recode(indicator, "PREP_NEW" = "PrEP_NEW"),
                  indicator = stringr::str_replace_all(indicator, " |  ", "_"),
                  agecoarse = dplyr::recode(agecoarse, "u15" = "<15", "o15" = "15+"),
                  sex = dplyr::recode(sex,
                                      "f" = "Female",
                                      "F" = "Female",
                                      "m" = "Male",
                                      "M" = "Male"),
                  otherdisaggregate = dplyr::recode(otherdisaggregate,
                                                    "u3mo" = "<3 months",
                                                    "35mo" = "3-5 months",
                                                    "o6mo" = "6 months or more"
                                                    #.default = as.character(NA)
                                                    ),
                  mech_code = stringr::str_remove(mech_code, "\\.0"),
                  mech_code = stringr::str_trim(mech_code)
                  )
  return(df)
}
USAID-OHA-SI/Wavelength documentation built on March 24, 2023, 10:07 a.m.