title: R - Composite functions vs piped functions in `purrr::map()`
body: <p>I have the following list:</p>
  
  <pre><code>my_list = list(alpha = list('hi'), 
                 beta = list(1:4, 'how'), 
                 gamma = list(TRUE, FALSE, 'are'))
  str(my_list)
  
  List of 3
   $ alpha:List of 1
    ..$ : chr "hi"
   $ beta :List of 2
    ..$ : int [1:4] 1 2 3 4
    ..$ : chr "how"
   $ gamma:List of 3
    ..$ : logi TRUE
    ..$ : logi FALSE
    ..$ : chr "are"
  </code></pre>
  
  <p>I would like to figure out which data types are contained within each level 1 element. To do this, I can use the following pipeline:</p>
  
  <pre><code>piped = map(my_list, ~map(., class) %&gt;% unique %&gt;% unlist)
  str(piped)
  List of 3
   $ alpha: chr "character"
   $ beta : chr [1:2] "integer" "character"
   $ gamma: chr [1:2] "logical" "character"
  </code></pre>
  
  <p>...which works as expected. But when I try to nest the call to <code>unique</code> inside <code>unlist()</code>, I get something different:</p>
  
  <pre><code>composite = map(my_list, ~map(., class) %&gt;% unlist(unique(.)))
  str(composite)
  List of 3
   $ alpha: chr "character"
   $ beta : chr [1:2] "integer" "character"
   $ gamma: chr [1:3] "logical" "logical" "character"
  </code></pre>
  
  <p>Could someone please help me understand why these two approaches are not equivalent?</p>