这不是为了举重,而是为了str_detect
在字符串和模式上进行矢量化,因此您可以将其与outer
函数来获得接近的东西:
library(stringr)
outer(files.in.path, strings.to.find, str_detect)
# [,1] [,2]
#[1,] TRUE FALSE
#[2,] TRUE FALSE
#[3,] TRUE TRUE
要检查字符串中是否存在所有模式,apply
the all
结果矩阵的每行逻辑运算符:
apply(outer(files.in.path, strings.to.find, str_detect), 1, all)
#[1] FALSE FALSE TRUE
或者按照@Jota 评论,stri_detect_fixed
如果您正在查看的模式应该完全匹配,那么在这里使用会更安全:
library(stringi)
apply(outer(files.in.path, strings.to.find, stri_detect_fixed), 1, all)
# [1] FALSE FALSE TRUE