Does a multi-value purrr::pluck exist?

前端 未结 4 860
既然无缘
既然无缘 2021-02-19 11:49

Seems like a basic question and perhaps I\'m just missing something obvious ... but is there any way to pluck a sublist (with purrr)? More specifically

4条回答
  •  情深已故
    2021-02-19 12:03

    There's clearly a need for "muti-value pluck". It really comes down to extending flexibility of "pluck" to retrieving multiple values from the same level of list, as described in this github issue. For the example above, you can probably get away with:

    > purrr::map(purrr::set_names(c("a", "b")), 
              ~purrr::pluck(l, .x, .default = NA_character_))
    #> $a
    #> [1] "foo"
    #> 
    #> $b
    #> [1] "bar"
    

提交回复
热议问题