R/split_psnu.R

Defines functions split_psnu

Documented in split_psnu

#' Clean & Separate PSNU and PSNU UIDS
#'
#' This function removes the contacanated data contained in the same cell. The
#' psnu column in the Target Setting Tool contains both the psnu, psnuuid, and meta data
#' on type - Country/SNU/DREAMS/Military. `split_psnu` breaks out psnu and
#' psnuuid into two columns and removes any other extraneous information.
#'
#' @param df Target Setting Tool data frame from tameDP
#'
#' @export

split_psnu <- function(df){

  df <- df %>%
    dplyr::mutate(psnu = psnu %>%
                    stringr::str_remove("^.*(?<=\\>)") %>%
                    stringr::str_remove_all(" \\[#(Country|SNU|DREAMS|Military)]") %>%
                    stringr::str_remove("(?<=\\]).*")) %>%
    tidyr::separate(psnu, c("psnu", "psnuuid", NA), sep = " \\[|]", fill = "right")

  return(df)
}
USAID-OHA-SI/tameDP documentation built on March 16, 2024, 6:26 a.m.