title: How to flatten a list to a list without coercion?
body: <p>I am trying to achieve the functionality similar to unlist, with the exception that types are not coerced to a vector, but the list with preserved types is returned instead. For instance:</p>
  
  <pre><code>flatten(list(NA, list("TRUE", list(FALSE), 0L))
  </code></pre>
  
  <p>should return</p>
  
  <pre><code>list(NA, "TRUE", FALSE, 0L)
  </code></pre>
  
  <p>instead of</p>
  
  <pre><code>c(NA, "TRUE", "FALSE", "0")
  </code></pre>
  
  <p>which would be returned by <code>unlist(list(list(NA, list("TRUE", list(FALSE), 0L))</code>.</p>
  
  <p>As it is seen from the example above, the flattening should be recursive. Is there a function in standard R library which achieves this, or at least some other function which can be used to easily and efficiently implement this?</p>
  
  <p><strong>UPDATE</strong>: I don't know if it is clear from the above, but non-lists should not be flattened, i.e. <code>flatten(list(1:3, list(4, 5)))</code> should return <code>list(c(1, 2, 3), 4, 5)</code>.</p>