是否有与 value = TRUE 的 grep 等效的 stringr?

Is there a stringr equivalent for grep with value = TRUE?

是否有 stringr 等同于 grepvalue 设置为 TRUE? (我想避免下面的 stringr 命令返回的 NAs。)

library(stringr)
x <- c("a", "b", "a")
grep("a", x, value = TRUE)  # returns "a" "a"
str_extract(x, "a")  # returns "a" NA  "a"

使用str_subset:

str_subset(x,"a")
[1] "a" "a"

帮助文件说明了等效性:

str_subset() is a wrapper around x[str_detect(x, pattern)], and is equivalent to grep(pattern, x, value = TRUE).