我正在尝试熟悉purrr
,map
并且pluck
我有一个嵌套很深的列表:
test_list <-
list(
outer_1 = list(
list(
inner_1 = list(pluck = "String I Want", dontpluck = "other string")
)
)
)
$outer_1
$outer_1[[1]]
$outer_1[[1]]$inner_1
$outer_1[[1]]$inner_1$pluck
[1] "String I want"
$outer_1[[1]]$inner_1$dontpluck
[1] "other string"
我想提取"String I want"
我知道我可以使用
test_list$outer_1[[1]]$inner_1$pluck
但我想用 map 来抽象这个,但我错过了一些步骤。(主要是我不知道如何模拟该[[1]]
部分使用map
- 比如:
map(test_list, "outer_1") %>%
map("inner_1") %>%
map("pluck")
期望的输出
[1] "String I want"