from https://stackoverflow.com/questions/58400176/r-find-object-by-name-in-deeply-nested-list

find_name(haystack, needle)

Arguments

haystack

Any object

needle

A named object within haystack

Value

The object named needle or NULL if needle was not found within haystack

Examples

l <- list("a" = sample(letters, 10), "b" = list("c" = sample(letters, 2), "d" = sample(letters, 4)))
find_name(l, "d")
#> [1] "x" "o" "m" "b"
find_name(l, "b")
#> $c
#> [1] "e" "z"
#> 
#> $d
#> [1] "x" "o" "m" "b"
#>