title: How to unnest a list containing data frames
body: <p>I'm trying to expand a nested column that contains a list of data frames.  They are either <code>NULL</code> or 1 row by n columns, so the goal is to just add n columns to the tibble.  (NULL list items would preferably expand to <code>NA</code>s).</p>
  
  <p>I've tried several solutions including those from <a href="https://stackoverflow.com/a/38860890/1086777">this answer</a>.</p>
  
  <p>The goal for the output would be a flat tibble with the following columns:
  full_address, address, location.x, location.y, score, attributes.StreetName, attributes.Match_addr.</p>
  
  
  
  <pre class="lang-r prettyprint-override"><code>require(tidyverse)
  #&gt; Loading required package: tidyverse
  
  df &lt;- structure(list(full_address = c("2379 ADDISON BLVD, HIGH POINT, NC 27262", 
                                  "1751 W LEXINGTON AVE, HIGH POINT, NC 27262", "2514 WILLARD DAIRY RD, HIGH POINT, NC 27265", 
                                  "126 MARYWOOD DR, HIGH POINT, NC 27265", "508 EDNEY RIDGE RD, GREENSBORO, NC 27408"
  ), json = list(NULL, NULL, structure(list(address = "2514 WILLARD DAIRY", 
                                            location = structure(list(x = -79.9766181813648, y = 36.0477204695356), class = "data.frame", row.names = 1L), 
                                            score = 92.8, attributes = structure(list(StreetName = "WILLARD DAIRY", 
                                                                                      Match_addr = "2514 WILLARD DAIRY"), class = "data.frame", row.names = 1L)), class = "data.frame", row.names = 1L), 
                 structure(list(address = "126 MARYWOOD, HIGH POINT", location = structure(list(
                   x = -80.0202617159213, y = 36.0077059145502), class = "data.frame", row.names = 1L), 
                   score = 97.24, attributes = structure(list(StreetName = "MARYWOOD", 
                                                              Match_addr = "126 MARYWOOD, HIGH POINT"), class = "data.frame", row.names = 1L)), class = "data.frame", row.names = 1L), 
                 structure(list(address = "508 EDNEY RIDGE RD", location = structure(list(
                   x = -79.840872836677, y = 36.1105523384593), class = "data.frame", row.names = 1L), 
                   score = 100L, attributes = structure(list(StreetName = "EDNEY RIDGE", 
                                                             Match_addr = "508 EDNEY RIDGE RD"), class = "data.frame", row.names = 1L)), class = "data.frame", row.names = 1L))), class = c("tbl_df", 
                                                                                                                                                                                            "tbl", "data.frame"), row.names = c(NA, -5L))
  
  df
  #&gt; # A tibble: 5 x 2
  #&gt;   full_address                                json                
  #&gt;   &lt;chr&gt;                                       &lt;list&gt;              
  #&gt; 1 2379 ADDISON BLVD, HIGH POINT, NC 27262     &lt;NULL&gt;              
  #&gt; 2 1751 W LEXINGTON AVE, HIGH POINT, NC 27262  &lt;NULL&gt;              
  #&gt; 3 2514 WILLARD DAIRY RD, HIGH POINT, NC 27265 &lt;data.frame [1 × 4]&gt;
  #&gt; 4 126 MARYWOOD DR, HIGH POINT, NC 27265       &lt;data.frame [1 × 4]&gt;
  #&gt; 5 508 EDNEY RIDGE RD, GREENSBORO, NC 27408    &lt;data.frame [1 × 4]&gt;
  
  
  df %&gt;% unnest(json)
  #&gt; Error: Argument 2 can't be a list containing data frames
  
  
  df %&gt;% map(unlist) %&gt;% as_data_frame()
  #&gt; Warning: `as_data_frame()` is deprecated, use `as_tibble()` (but mind the new semantics).
  #&gt; This warning is displayed once per session.
  #&gt; Tibble columns must have consistent lengths, only values of length one are recycled:
  #&gt; * Length 5: Column `full_address`
  #&gt; * Length 18: Column `json`
  
  df %&gt;%
    mutate_if(is.list, simplify_all) %&gt;%    # flatten each list element internally 
    unnest() 
  #&gt; Error: Argument 2 can't be a list containing data frames
  </code></pre>
  
  <p><sup>Created on 2019-04-19 by the <a href="https://reprex.tidyverse.org" rel="nofollow noreferrer">reprex package</a> (v0.2.1)</sup></p>