title: Tricks to manage the available memory in an R session
body: <p>What tricks do people use to manage the available memory of an interactive R session?  I use the functions below [based on postings by Petr Pikal and David Hinds to the r-help list in 2004] to list (and/or sort) the largest objects and to occassionally <code>rm()</code> some of them. But by far the most effective solution was ... to run under 64-bit Linux with ample memory. </p>
  
  <p>Any other nice tricks folks want to share?  One per post, please.</p>
  
  <pre><code># improved list of objects
  .ls.objects &lt;- function (pos = 1, pattern, order.by,
                          decreasing=FALSE, head=FALSE, n=5) {
      napply &lt;- function(names, fn) sapply(names, function(x)
                                           fn(get(x, pos = pos)))
      names &lt;- ls(pos = pos, pattern = pattern)
      obj.class &lt;- napply(names, function(x) as.character(class(x))[1])
      obj.mode &lt;- napply(names, mode)
      obj.type &lt;- ifelse(is.na(obj.class), obj.mode, obj.class)
      obj.size &lt;- napply(names, object.size)
      obj.dim &lt;- t(napply(names, function(x)
                          as.numeric(dim(x))[1:2]))
      vec &lt;- is.na(obj.dim)[, 1] &amp; (obj.type != "function")
      obj.dim[vec, 1] &lt;- napply(names, length)[vec]
      out &lt;- data.frame(obj.type, obj.size, obj.dim)
      names(out) &lt;- c("Type", "Size", "Rows", "Columns")
      if (!missing(order.by))
          out &lt;- out[order(out[[order.by]], decreasing=decreasing), ]
      if (head)
          out &lt;- head(out, n)
      out
  }
  # shorthand
  lsos &lt;- function(..., n=10) {
      .ls.objects(..., order.by="Size", decreasing=TRUE, head=TRUE, n=n)
  }
  </code></pre>