title: Unnesting a data frame containing lists
body: <p>I have a data frame that contains lists, like below:</p>
  
  
  
  <pre class="lang-r prettyprint-override"><code># Load packages
  library(dplyr)
  
  # Create data frame
  df &lt;- structure(list(ID = 1:3, 
                       A = structure(list(c(9, 8), c(7,6), c(6, 9)), ptype = numeric(0), class = c("vctrs_list_of", "vctrs_vctr")), 
                       B = structure(list(c(3, 5), c(2, 6), c(1, 5)), ptype = numeric(0), class = c("vctrs_list_of", "vctrs_vctr")), 
                       C = structure(list(c(6, 5), c(7, 6), c(8, 7)), ptype = numeric(0), class = c("vctrs_list_of", "vctrs_vctr")), 
                       D = structure(list(c(5, 3), c(4, 1), c(6,  5)), ptype = numeric(0), class = c("vctrs_list_of", "vctrs_vctr"))), 
                  row.names = c(NA, -3L), class = c("tbl_df", "tbl", "data.frame"))
  
  # Peek at data 
  df
  #&gt; # A tibble: 3 x 5
  #&gt;      ID A         B         C         D        
  #&gt;   &lt;int&gt; &lt;list&gt;    &lt;list&gt;    &lt;list&gt;    &lt;list&gt;   
  #&gt; 1     1 &lt;dbl [2]&gt; &lt;dbl [2]&gt; &lt;dbl [2]&gt; &lt;dbl [2]&gt;
  #&gt; 2     2 &lt;dbl [2]&gt; &lt;dbl [2]&gt; &lt;dbl [2]&gt; &lt;dbl [2]&gt;
  #&gt; 3     3 &lt;dbl [2]&gt; &lt;dbl [2]&gt; &lt;dbl [2]&gt; &lt;dbl [2]&gt;
  </code></pre>
  
  <p>I'd like to unnest the lists and can do so using <code>pmap_dfr</code>.</p>
  
  <pre class="lang-r prettyprint-override"><code># Expand rows
  df %&gt;% purrr::pmap_dfr(function(...)data.frame(...))
  #&gt;   ID A B C D
  #&gt; 1  1 9 3 6 5
  #&gt; 2  1 8 5 5 3
  #&gt; 3  2 7 2 7 4
  #&gt; 4  2 6 6 6 1
  #&gt; 5  3 6 1 8 6
  #&gt; 6  3 9 5 7 5
  </code></pre>
  
  <p><sup>Created on 2019-06-28 by the <a href="https://reprex.tidyverse.org" rel="nofollow noreferrer">reprex package</a> (v0.3.0)</sup></p>
  
  <p>This is the desired result, but seems to be reinventing the wheel because <code>tidyr::unnest</code> is designed to flatten list columns back to regular columns. Using <code>tidyr::unnest</code> produces the following error, however:</p>
  
  <pre class="lang-r prettyprint-override"><code>df %&gt;% unnest(cols = c(A, B, C, D))
  #Error: No common type for `x` &lt;tbl_df&lt;A:double&gt;&gt; and `y` &lt;double&gt;.
  #Call `rlang::last_error()` to see a backtrace
  </code></pre>
  
  <p>How would I apply <code>unnest</code> in this case for flattening my data frame with list columns?</p>
  
  <hr>
  
  <h3>Version information</h3>
  
  <pre class="lang-r prettyprint-override"><code>&gt; packageVersion("tidyr")
  [1] ‘0.8.3.9000’
  </code></pre>