I hope this isn't to complicated but this script is the simplest I could do. The problem is, that i have a list, containing other lists, containing other lists, containg other lists, containing vectors.
#!/bin/env Rscript
suppressMessages(library("tidyverse"))
# A distinct analysis.
level3.list1 <- list(
key1 = "name 1"
, key2 = 14
, key3 = 15
, key4 = c(15, 29, 43, 57)
, key5 = 332
, key6 = c("A", "B", "C")
)
level3.list2 <- list(
key1 = "name 2"
, key2 = 28
, key3 = 15
, key4 = c(15, 43, 71, 99)
, key5 = 332
, key6 = c("Y", "Z")
)
level3.list3 <- list(
key1 = "name 3"
, key2 = 56
, key3 = 22
, key4 = c(78, 134, 190, 246)
, key5 = 112
, key6 = c("V")
)
# Grouped analyses.
level2.list1 <- list( level3.list1, level3.list2 )
level2.list2 <- list( level3.list3 )
# Planned samplings.
level1.list1 <- list(
code = "ABC123"
, type = "spot"
, matrix = "water"
, analyses = level2.list1
)
level1.list2 <- list(
code = "GHS332"
, type = "mix"
, matrix = "water"
, analyses = level2.list2
)
# All the samplings.
level0.list <- list(level1.list1, level1.list2)
# "Flattening".
map_dfr(level0.list, ~.)
# Gives at least:
# A tibble: 3 × 4
# code type matrix analyses
# <chr> <chr> <chr> <list>
#1 ABC123 spot water <named list [6]>
#2 ABC123 spot water <named list [6]>
#3 GHS332 mix water <named list [6]>
Is this understandable?