Skip to content

Instantly share code, notes, and snippets.

@jrosell
Created February 28, 2024 13:45
Show Gist options
  • Save jrosell/faa0e59c9e0bd1db27f37ae0f0f9710f to your computer and use it in GitHub Desktop.
Save jrosell/faa0e59c9e0bd1db27f37ae0f0f9710f to your computer and use it in GitHub Desktop.
library(tidyverse)
x <- list(a = list(b = 1, c = NULL), d = NULL)
get_list_names <- \(x, y = c()){
if (!is.null(names(x))){
for (nm in names(x)) {
y <- get_list_names(x[[nm]], c(y, nm))
}
}
return(y)
}
get_list_names(x)
"c" %in% get_list_names(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment