Making a small sample dataset (See this SO post).
l <- list(
list(id = "a", title = "blabla trailer"),
list(id = "b", title = "keep this one"),
list(id = "c", title = "remove this match"))
To subset list elements based on search patterns we can use some regular expression to find matches those matches. We can use |
to search for multiple possibilities.
# base R
l[!sapply(l, function(x){grepl("match|highlight|trailer", x$title)})]
# purrr
library(purrr)
l[!map_lgl(l, ~ grepl("match|highlight|trailer", .x$title))]
[[1]]
[[1]]$id
[1] "b"
[[1]]$title
[1] "keep this one"