Retrieving Nested Items from a List

I am trying to get nested items from a list. I can extract the elements using:, unlist(pull_lists[[i]]$content[[n]]['sha'])however it seems that I cannot insert them into a nested list. I highlighted the only list item at the core that creates the reproducible example below. Here is what I still have:

library("devtools")
pull_lists <- list(source_gist("669dfeccad88cd4348f7"))

sha_list <- list()
for (i in length(pull_lists)){
  for (n in length(pull_lists[[i]]$content)){
  sha_list[i][n] <- unlist(pull_lists[[i]]$content[[n]]['sha'])
  }
}

How can I insert elements in a nested way?

+2
source share
1 answer

When I upload content, I get a much more complex structure than you. For me it is not pull_lists[[i]]$content, it pull_lists[[i]]$value$content[[1 or 2]]$parents$sha. The reason that nothing is populated is because nothing exists there (i.e. N = 0).

. , , .

:

sha_locations <- grep("sha$",names(unlist(pull_list[[1]])))
unlist(pull_list[[1]])[sha_locations] 

for , :

sha_list <- lapply(
   pull_list, 
   function(x) unlist(x)[grep("sha$",names(unlist(x)))]
)

SHA, SHA , SHA:

sha_list <- sha_list[[1]][attr(sha_list[[1]], "names")=="value.content.sha"]
+1

All Articles