Skip to content

Instantly share code, notes, and snippets.

@MrFlick
MrFlick / find_name_index.R
Created June 8, 2023 14:17
Find index of name in nested list
find_name_index <- function(haystack, needle, idx=c()) {
if (hasName(haystack, needle)) {
c(idx, which(names(haystack)==needle))
} else if (is.list(haystack)) {
for (i in seq_along(haystack)) {
obj <- haystack[[i]]
ret <- Recall(obj, needle, c(idx,i))
if (!is.null(ret)) return(ret)
}
} else {