extracting data from deeply nested list

Consider the structure of this list:

How can I access PERMDISP$Actinobacteria@bdisp$SampleType$model$distances using purrr?

Furthermore, I would like to make a tibble containing the distances for all PERMDISP names

names(PERMDISP)
[1] "Actinobacteria" "Acidobacteria" "Verrucomicrobia" "Firmicutes"

Many thanks in advance!

In general, you're not supposed to use @ to access data within objects: these are slots of S4 objects, and usually the package developer should provide accessor functions so you can get this data without using @ (though it's sometimes convenient as a user).

I'm not familiar with {microViz}, but it seems to me you want to use bdisp_get(), described in this manpage (if you look at its source code, you may notice it's basically just doing @bdisp with some checks).

So for your question, I would suggest something like

map(PERMDISP
 \(species){
    bdisp_get(species) |>
      pluck("SampleType", "model", "distances")
})

(code not tested)

Thanks a lot!
It worked perfectly

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.