You are just passing the pattern argument, but you are missing the string argument, so the function doesn't have nothing to replace.
library(stringr)
text = c("apples and oranges and pears and bananas")
str_replace_all(string = text,
pattern = c('apples' = "pineapples",
'oranges' = "strawberries")
)
#> [1] "pineapples and strawberries and pears and bananas"
For a dataframe and with dplyr you need to use it this way
library(dplyr)
library(stringr)
fruits <- data.frame(
col = c("apples and oranges and pears and bananas",
"pineapples and mangos and guavas")
)
fruits %>%
mutate(col = str_replace_all(col, pattern = c('apples' = "pineapples",
'oranges' = "strawberries")))
#> col
#> 1 pineapples and strawberries and pears and bananas
#> 2 pinepineapples and mangos and guavas