title: A better way to push and pop to/from lists in R?
body: <p>If <code>foo &lt;- list()</code>, I find myself writing <code>foo[[length(foo)+1]] &lt;- bar</code> a lot when really I just want to write <code>push(foo, bar)</code>.</p>
  
  <p>Similarly (though much less frequently) <code>bar &lt;- foo[[length(foo)]]</code> would be much nicer as <code>bar &lt;- pop(foo)</code>.</p>
  
  <ol>
  <li>Is there a better way to do this in base R?</li>
  <li>Failing that, has anyone written a package that makes these basic list operations less syntactically torturous?  </li>
  </ol>
  
  <p>It's the repetition of the variable name that kills me.  Consider:</p>
  
  <pre><code>anInformative.selfDocumenting.listName[[length(anInformative.selfDocumenting.listName)+1]] &lt;- bar
  </code></pre>
  
  <hr>
  
  <p>edit:  </p>
  
  <p><code>foo &lt;- append(foo, bar)</code> doesn't work for me</p>
  
  <pre><code>foo &lt;- list()
  for (i in 1:10) {
    x &lt;- data.frame(a=i, b=rnorm(1,0,1))
    foo[[length(foo)+1]] &lt;- x
  }
  str(foo)
  </code></pre>
  
  <p>Gives a list of 10 objects as expected.</p>
  
  <pre><code>foo &lt;- list()
  for (i in 1:10) {
    x &lt;- data.frame(a=i, b=rnorm(1,0,1))
    foo &lt;- append(foo, x)
  }
  str(foo)
  </code></pre>
  
  <p>Gives a list of 20 objects.</p>