Reputation: 469
I have an output that I receive from a Shiny app i'm building. The output looks like this:
[1] "wrong item" "Wrong order" "completely wrong"
it appears to be tab delimited but i'm not event sure of the format. I would need to be able to convert it to a pipe delimited list such as
df %>%
filter(str_detect(string, wrong item|Wrong order|completely wrong"))
is it possible at all? As a starting point I've tried to convert the output to a list but it's not letting me as there's no comma:
l<-paste("wrong item" "Wrong order" "completely wrong")
Thank you if you can help me it would be much appreciated.
Upvotes: 0
Views: 42
Reputation: 79194
I think you need something like this?:
#If your output is x
x <- c("wrong item", "Wrong order", "completely wrong")
paste(x, collapse = "|")
# will give:
# [1] "wrong item|Wrong order|completely wrong"
# so in your example it could be:
library(dplyr)
library(stringr)
df %>%
filter(str_detect(string, paste(x, collapse = "|")))
# OR
df %>%
filter(str_detect(string, paste(c( "wrong item", "Wrong order", "completely wrong"), collapse = "|")))
Upvotes: 3