rename strings (multiple options)

PHOTO EMBED

Tue May 30 2023 13:23:33 GMT+0000 (Coordinated Universal Time)

Saved by @vs #r

# convert strings to sentence case
stringr::str_to_sentence(c("aaa", "BBB")) # -> "Aaa", "Bbb"

# rename multiple values
patterns <- list(
  "old1" = "new1",
  "old2" = "new2"
)
stringi::stri_replace_all_regex(
  c("old1 value", "old2 value"),
  pattern = names(patterns),
  replacement = unlist(patterns),
  vectorize_all = FALSE
) # -> "new1 value" "new2 value"
content_copyCOPY