purrr - 在地图调用中使用完整的列表元素

purrr - use full list-elements in map call

具有以下列表:

dat <- list(words = c("foo", "bar", "howdy"), 
        pattern=c(foobar="foo|bar", cowboy="howdy"), 
        furterdat=1)

我想用管道式的方式做以下事情

require(purrr)
require(stringr)
map(dat$pattern, ~str_detect(dat$words, .))

我试过这样想

dat %>% map(.$pattern, ~str_detect, string=.$words)
dat %>% lmap(.$pattern, ~str_detect, string=.$words)

但是得不到我想要的结果。有什么想法吗?

以下为选项:

library(purrr)
library(stringr)

dat <- list(words = c("foo", "bar", "howdy"), 
        pattern=c(foobar="foo|bar", cowboy="howdy"), 
        furterdat=1)

dat$pattern %>% map(str_detect, dat$words)

#> $foobar
#> [1]  TRUE  TRUE FALSE
#> 
#> $cowboy
#> [1] FALSE FALSE  TRUE