title: Here we go again: append an element to a list in R
body: <p>I am not happy with the accepted answer to <a href="https://stackoverflow.com/questions/2436688/append-an-object-to-a-list-in-r-in-amortized-constant-time">Append an object to a list in R in amortized constant time?</a></p>
  
  <pre><code>&gt; list1 &lt;- list("foo", pi)
  &gt; bar &lt;- list("A", "B")
  </code></pre>
  
  <p>How can I append new element <code>bar</code> to <code>list1</code>? Clearly, <code>c()</code> does not work, it flattens <code>bar</code>:</p>
  
  <pre><code>&gt; c(list1, bar)
  [[1]]
  [1] "foo"
  
  [[2]]
  [1] 3.141593
  
  [[3]]
  [1] "A"
  
  [[4]]
  [1] "B"
  </code></pre>
  
  <p>Assignment to index works:</p>
  
  <pre><code>&gt; list1[[length(list1)+1]] &lt;- bar
  &gt; list1
  [[1]]
  [1] "foo"
  
  [[2]]
  [1] 3.141593
  
  [[3]]
  [[3]][[1]]
  [1] "A"
  
  [[3]][[2]]
  [1] "B"
  </code></pre>
  
  <p>What is the efficiency of this method? Is there a more elegant way?</p>