I have a string and would like to capitalize two lowercase words. The following accomplishes what I want:
library(tidyverse)
"this is a test" %>%
str_replace_all("this", toupper("this")) %>%
str_replace_all("test", toupper("test"))
However, I would like to do this in a more efficient way as I have a lot of patterns to replace and do not want a separate line per pattern. I thought about using map, however I cannot get it to execute properly as the code below throws an error:
"this is a test" %>%
c("this", "test") %>%
map_chr(~str_replace_all(.x, toupper(.x)))
Can anyone tell me how to accomplish this?