data-raw/fns/replace.R

replace_abbr <- function(title_chr,
                         abbreviations_lup,
                         collapse_lgl = T) {
  title_chr <- title_chr %>%
    strsplit(" ") %>%
    purrr::flatten_chr() %>%
    purrr::map_chr(~ {
      match_lgl_vec <- .x == abbreviations_lup$short_name_chr
      ifelse(match_lgl_vec %>%
        any(),
      ifelse(.x %in% abbreviations_lup$short_name_chr[match_lgl_vec],
        ready4::get_from_lup_obj(abbreviations_lup,
          match_value_xx = ifelse(.x == abbreviations_lup$short_name_chr[match_lgl_vec],
            .x,
            abbreviations_lup$short_name_chr[match_lgl_vec]
          ),
          match_var_nm_1L_chr = "short_name_chr",
          target_var_nm_1L_chr = "long_name_chr",
          evaluate_1L_lgl = F
        ),
        .x
      ),
      .x
      )
    })
  if (collapse_lgl) {
    title_chr <- title_chr %>% paste0(collapse = " ")
  }
  return(title_chr)
}
ready4-dev/ready4fun documentation built on April 22, 2024, 8:33 a.m.