It does, but I fear my reprex was too minimal. Adding an additional row causes flatten() to duplicate the unnested columns and discard their names.
library(tidyverse)
mongo_return <-
structure(list(
chamber = c("House", "House"),
party_code = c(200L, 100L),
bioname = c("ABRAHAM, Ralph", "ADAMS, Alma"),
twitter = c("RepAbraham", "RepAdams"),
nominate = structure(list(
dim2 = c(0.276, 0.023),
log_likelihood = c(-87.3178688959091, -58.4741390664067),
dim1 = c(0.509, -0.469),
conditional = c(1L, 1L),
number_of_votes = c(950L, 938L),
geo_mean_probability = c(0.912184007904348, 0.939564163164169),
number_of_errors = c(27L, 25L),
total_number_of_votes = c(2105L, 2052L)
),
row.names = c(NA, -2L), class = "data.frame"
)
),
row.names = c(NA, -2L), class = "data.frame"
)
# still works
bind_cols(
mongo_return %>% select(-nominate),
mongo_return %>% pull(nominate)
) %>% glimpse()
#> Observations: 2
#> Variables: 12
#> $ chamber <chr> "House", "House"
#> $ party_code <int> 200, 100
#> $ bioname <chr> "ABRAHAM, Ralph", "ADAMS, Alma"
#> $ twitter <chr> "RepAbraham", "RepAdams"
#> $ dim2 <dbl> 0.276, 0.023
#> $ log_likelihood <dbl> -87.31787, -58.47414
#> $ dim1 <dbl> 0.509, -0.469
#> $ conditional <int> 1, 1
#> $ number_of_votes <int> 950, 938
#> $ geo_mean_probability <dbl> 0.9121840, 0.9395642
#> $ number_of_errors <int> 27, 25
#> $ total_number_of_votes <int> 2105, 2052
# drops unnested col names
mongo_return %>%
purrr::flatten() %>%
as_tibble(.name_repair = "unique") %>%
glimpse()
#> New names:
#> * `` -> ...1
#> * `` -> ...2
#> * `` -> ...3
#> * `` -> ...4
#> * `` -> ...5
#> * ... and 3 more problems
#> Observations: 2
#> Variables: 16
#> $ ...1 <chr> "House", "House"
#> $ ...2 <chr> "House", "House"
#> $ ...3 <int> 200, 200
#> $ ...4 <int> 100, 100
#> $ ...5 <chr> "ABRAHAM, Ralph", "ABRAHAM, Ralph"
#> $ ...6 <chr> "ADAMS, Alma", "ADAMS, Alma"
#> $ ...7 <chr> "RepAbraham", "RepAbraham"
#> $ ...8 <chr> "RepAdams", "RepAdams"
#> $ dim2 <dbl> 0.276, 0.023
#> $ log_likelihood <dbl> -87.31787, -58.47414
#> $ dim1 <dbl> 0.509, -0.469
#> $ conditional <int> 1, 1
#> $ number_of_votes <int> 950, 938
#> $ geo_mean_probability <dbl> 0.9121840, 0.9395642
#> $ number_of_errors <int> 27, 25
#> $ total_number_of_votes <int> 2105, 2052
Created on 2019-10-08 by the reprex package (v0.3.0)