title: How to set_names on a list column using the tidyverse: tibble, purrr, dplyr
body: <p>Short version, I would like to be able to <code>set_names()</code> on a "list-column" returned from a <code>summarise()</code> function. So if I have a list-column that uses the <code>range()</code> function, I would like to be able to set the names as "min" and "max". </p>
  
  <p>Below are the details and a reproducible example.</p>
  
  
  
  <pre class="lang-r prettyprint-override"><code>library(tidyverse)
  
  # Consider the following:
  msleep %&gt;%
    group_by(vore) %&gt;%
    summarise(
      sleep_total_range = list(range(sleep_total))
    )
  #&gt; # A tibble: 5 x 2
  #&gt;   vore    sleep_total_range
  #&gt;   &lt;chr&gt;   &lt;list&gt;           
  #&gt; 1 carni   &lt;dbl [2]&gt;        
  #&gt; 2 herbi   &lt;dbl [2]&gt;        
  #&gt; 3 insecti &lt;dbl [2]&gt;        
  #&gt; 4 omni    &lt;dbl [2]&gt;        
  #&gt; 5 &lt;NA&gt;    &lt;dbl [2]&gt;
  
  # I would like to be able to identify and label (i.e., set_names()) for the 
  # min and max columns
  
  # Fail 1: No Column, No Labels
  msleep %&gt;%
    group_by(vore) %&gt;%
    summarise(
      sleep_total_range = list(range(sleep_total))
    ) %&gt;% 
    unnest()
  #&gt; # A tibble: 10 x 2
  #&gt;    vore    sleep_total_range
  #&gt;    &lt;chr&gt;               &lt;dbl&gt;
  #&gt;  1 carni                 2.7
  #&gt;  2 carni                19.4
  #&gt;  3 herbi                 1.9
  #&gt;  4 herbi                16.6
  #&gt;  5 insecti               8.4
  #&gt;  6 insecti              19.9
  #&gt;  7 omni                  8  
  #&gt;  8 omni                 18  
  #&gt;  9 &lt;NA&gt;                  5.4
  #&gt; 10 &lt;NA&gt;                 13.7
  
  # Fail 2: Column, but labels are not correct
  msleep %&gt;%
    group_by(vore) %&gt;%
    summarise(
      sleep_total_range = list(range(sleep_total) %&gt;% enframe(name = "range_col"))
    ) %&gt;% 
    unnest()
  #&gt; # A tibble: 10 x 3
  #&gt;    vore    range_col value
  #&gt;    &lt;chr&gt;       &lt;int&gt; &lt;dbl&gt;
  #&gt;  1 carni           1   2.7
  #&gt;  2 carni           2  19.4
  #&gt;  3 herbi           1   1.9
  #&gt;  4 herbi           2  16.6
  #&gt;  5 insecti         1   8.4
  #&gt;  6 insecti         2  19.9
  #&gt;  7 omni            1   8  
  #&gt;  8 omni            2  18  
  #&gt;  9 &lt;NA&gt;            1   5.4
  #&gt; 10 &lt;NA&gt;            2  13.7
  </code></pre>
  
  <p>Desired Results</p>
  
  <pre class="lang-r prettyprint-override"><code># Success: This is my desired result/output, but it feels verbose, 
  # and not very "tidyverse / purrr"
  msleep %&gt;%
    group_by(vore) %&gt;%
    summarise(
      sleep_total_range = list(range(sleep_total) %&gt;% enframe(name = "range_col"))
    ) %&gt;% 
    unnest() %&gt;%
    mutate(
      range_col = ifelse(range_col == 1, "min", "max")
    )
  #&gt; # A tibble: 10 x 3
  #&gt;    vore    range_col value
  #&gt;    &lt;chr&gt;   &lt;chr&gt;     &lt;dbl&gt;
  #&gt;  1 carni   min         2.7
  #&gt;  2 carni   max        19.4
  #&gt;  3 herbi   min         1.9
  #&gt;  4 herbi   max        16.6
  #&gt;  5 insecti min         8.4
  #&gt;  6 insecti max        19.9
  #&gt;  7 omni    min         8  
  #&gt;  8 omni    max        18  
  #&gt;  9 &lt;NA&gt;    min         5.4
  #&gt; 10 &lt;NA&gt;    max        13.7
  </code></pre>
  
  <p>Close but not yet...</p>
  
  <pre class="lang-r prettyprint-override"><code># I thought I was close with this
  temp &lt;- 
  msleep %&gt;%
    group_by(vore) %&gt;%
    summarise(
      sleep_total_range = list(range(sleep_total))
    )
  
  temp$sleep_total_range[[1]] %&gt;% set_names(c("min", "max")) %&gt;% enframe()
  #&gt; # A tibble: 2 x 2
  #&gt;   name  value
  #&gt;   &lt;chr&gt; &lt;dbl&gt;
  #&gt; 1 min     2.7
  #&gt; 2 max    19.4
  
  # But this obviously does not work...
  msleep %&gt;%
    group_by(vore) %&gt;%
    summarise(
      sleep_total_range = list(range(sleep_total)) %&gt;% 
          set_names(c("min", "max")) %&gt;% 
          enframe()
    )
  #&gt; `nm` must be `NULL` or a character vector the same length as `x`
  </code></pre>
  
  <p><sup>Created on 2019-07-18 by the <a href="https://reprex.tidyverse.org" rel="nofollow noreferrer">reprex package</a> (v0.3.0)</sup></p>