I have a nested list with some elements as empty list (extract):
str(myList)
List of 100
$ :'data.frame': 2 obs. of 10 variables:
..$ _index : chr [1:2] "alias_fr" "alias_fr"
..$ _type : chr [1:2] "triplet" "triplet"
..$ _id : chr [1:2] "Q9327" "Q3122270"
$ : list()
$ :'data.frame': 1 obs. of 9 variables:
..$ _index : chr "alias_fr"
..$ _type : chr "triplet"
..$ _id : chr "Q17009"
I need to index each element, using bind_rows:
df <- bind_rows(myList, .id = "id")
Unfortunately, the empty elements (second one in the example) are deleted, the consequences being a bad indexing (shift of indexes):
id _index _type _id
1 1 alias_fr triplet Q9327
2 1 alias_fr triplet Q3122270
3 2 alias_fr triplet Q17009
What I expect:
id _index _type _id
1 1 alias_fr triplet Q9327
2 1 alias_fr triplet Q3122270
3 2 NA NA NA
3 3 alias_fr triplet Q17009
I have already tried several methods without any success:
Convert R list to dataframe with missing/NULL elements ...
Is there a way to make the empty elements taken into account with bind_rows?