To clean some messy data I would like to start using pipes %>%
, but I fail to get the R code working if gsub()
is not at the beginning of the pipe,
You can use str_replace(string, pattern, replacement) from package stringr as a drop-in replacement for gsub
. stringr functions follow a tidy approach in which the string / character vector is the first argument.
c("hello", "hi") %>% str_replace_all("[aeiou]", "x")
See Introduction to stringr for more information on stringr's sensibly named and defined functions as replacements for R's default string functions.