Let\'s say I have a long character string: pneumonoultramicroscopicsilicovolcanoconiosis. I\'d like to use stringr::str_replace_all to replace certain letters w
My workaround would be to take advantage of the fact that str_replace_all can take functions as an input for the replacement.
library(stringr)
text_string = "developer"
pattern <- "p|e"
fun <- function(query) {
if(query == "e") y <- "p"
if(query == "p") y <- "e"
return(y)
}
str_replace_all(text_string, pattern, fun)
Of course, if you need to scale up, I would suggest to use a more sophisticated function.