Consider this convoluted and nested example (which, believe it or not arises for real in my dataset)
> nestedlist <- list(list('fakedata' = 'hello',
+ list(list('name'= list('john','litz'), 'age'= 30))),
+ list('fakedata' = 'there',
+ list(list('name'= list('frank','doe'), 'age'= 34))))
>
> nestedlist %>% str
List of 2
$ :List of 2
..$ fakedata: chr "hello"
..$ :List of 1
.. ..$ :List of 2
.. .. ..$ name:List of 2
.. .. .. ..$ : chr "john"
.. .. .. ..$ : chr "litz"
.. .. ..$ age : num 30
$ :List of 2
..$ fakedata: chr "there"
..$ :List of 1
.. ..$ :List of 2
.. .. ..$ name:List of 2
.. .. .. ..$ : chr "frank"
.. .. .. ..$ : chr "doe"
.. .. ..$ age : num 34
I am trying to use purrr to extract elements from it. Something simple like extracting the fakedata field works easily:
> purrr::map(nestedlist, 'fakedata')
[[1]]
[1] "hello"
[[2]]
[1] "there"
However, I am interested in the name field. And in this case my purrr solution does not work:
> purrr::map(nestedlist, list(1,1,'name'))
[[1]]
NULL
[[2]]
NULL
What is the issue here? Thanks!