Can not run the code of str_remove


#1

Below codes I copied from an example in this community:

fruits <- c("one apple", "two pears", "three bananas")
str_remove(fruits, "[aeiou]")
str_remove_all(fruits, "[aeiou]")

But when I run it, there was a warning for str_remove(fruits, "[aeiou]") such:
Error in str_replace_all(., pattern = remove_words %>% paste0("(", ., :
could not find function "str_replace_all"
and str_remove_all(fruits, "[aeiou]") such:
Error during wrapup: could not find function "str_remove_all"

Can anyone please explain why the codes were not working?


#2

Hi there, @ferkingshelby! Did you load the stringr package before running this example? It comes with the tidyverse but isn't attached when you load it, so you'll need to separately run library(stringr) in order to access functions like str_remove(). That might be the problem you're having!


#3

Thank you so much @rensa. Now it works perfectly! Sorry I am newbie in R so not quite familiar with command. :slight_smile:


#4

That's okay! Glad we could help :smile:


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.