"Master" of string manipulation

it's sarcasm, y'see?

By Jesse Mostipak in learning

June 8, 2021

I have literally never been able to remember how to use {stringr} functions within the filter() function. It doesn’t come up often in my work, but every time it does I do a Google and then smack my forehead and go “oh yeeeeaaaaaaah.”

I can tell you exactly why it doesn’t stick, too. In 99.99% of my filter() functions the pattern is something like this:

data %>% 
  filter(column_name == value)

But when you use filter() with a {stringr} function, it looks like this:

data %>% 
  filter(str_detect(column_name, "regular_expression_pattern"))

So of course literally every time I want to use a {stringr} function with filter() I do this:

data %>% 
  filter(column_name == str_detect("pattern"))

…and it never ends well.

So thank you (again and again and again) to the Twitch chat fam from last night walking me through this!

Posted on:
June 8, 2021
1 minute read, 135 words
stringr R
See Also:
Stream makes a streamplot
Surviving #TidyTuesday
Data Science Twitch Streamers Round Up