title: Monitor memory usage in R
body: <p>Is it possible to monitor the amount of memory that is in use or has been used by R to call a function? For example, I have an arbitrary function, e.g:</p>
  
  <pre><code>smallest.sv &lt;- function(){
    A &lt;- matrix(rnorm(1e6), 1e3);
    mysvd &lt;- svd(A);
    return(tail(mysvd$d, 1));
  }
  </code></pre>
  
  <p>Running the function simply returns a scalar, but a lot of memory was used to calculate the function. Now I need to do performance benchmarking. Processing time is easy:</p>
  
  <pre><code>system.time(x &lt;- smallest.sv())
  </code></pre>
  
  <p>However I would also like to know how much memory was needed for this call, without modifying the function (it should work for arbitrary functions). Is there any way to do this?</p>
  
  <p>Edit: to clarify a bit. I am mostly interested in the upper bound of memory that was in use during the call of the function, i.e. how much physical memory is required to be able to process the function call. In many cases this is significantly less than the total amount of allocated memory I think.</p>