-1

I am new to tidyverse. I have this clunky code that combines a lot of functions together

flow[grep(paste(paste(series, "J8","F", sep = "."), "TEMP",sep = "_")
                         , flow$Final.code), -1]

flow is a dataset.

is there a way for me to rewrite this code using piper so that it's easier to see?

Rainroad
  • 191
  • 8
  • It's hard to really help without a representative sample of data. [See here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on making an R question that's easier to help with. Also guessing that by "piper", you mean `magrittr`/`dplyr`-style pipes? – camille Jul 25 '19 at 21:41

1 Answers1

0

One way could be:

flow %>%
  filter(str_detect(NAME_OF_-1_COLUMN, paste(paste(series, "J8","F", sep = "."), "TEMP", sep = "_")))

It's not entirely clear what your data is so I can't be sure this is a perfect solution. This doesn't work if you are using your grep command to reference row names. If you wanted to go full tidyverse, replace paste() with str_c().

You can also assign the paste-ception to a variable and just use that if readability is the concern:

things_to_detect = paste(paste(series, "J8","F", sep = "."), "TEMP", sep = "_")

flow %>%
  filter(str_detect(NAME_OF_-1_COLUMN, things_to_detect))
MokeEire
  • 638
  • 1
  • 8
  • 19