pull all elements with specific name from a nested list

后端 未结 4 1929
谎友^
谎友^ 2021-01-16 13:38

I have some archived Slack data that I am trying to get some of key message properties. I\'d done this by stupidly flattening the entire list, getting a data.frame or tibble

4条回答
  •  佛祖请我去吃肉
    2021-01-16 14:18

    As OP mentioned, this can solve the issue:

    #Code
    unlist(l)[grepl('.type',names(unlist(l)),fixed=T)]
    

    Output:

    folder_1.msg_1-1.type folder_1.msg_1-2.type folder_2.msg_2-1.type 
                "message"             "message"             "message" 
    

    Another options are (Many thanks and credit to @Abdessabour Mtk)

    #Code1
    purrr::map(l, ~ purrr::map(.x, "type"))
    

提交回复
热议问题