title: R: how to make system.time print the expression being timed?
body: <p>I have a big agglomeration of <code>R</code> functions calling each other, they may take a lot of time, so I call them using <a href="http://stat.ethz.ch/R-manual/R-patched/library/base/html/system.time.html" rel="nofollow noreferrer"><code>system.time</code></a>:</p>
  <pre><code>f1 &lt;- function () {
    print(system.time(f1.1()))
    print(system.time(f1.2()))
    print(system.time(f1.3()))
  }
  ...
  f &lt;- function () {
    print(system.time(f1()))
    print(system.time(f2()))
    print(system.time(f3()))
  }
  </code></pre>
  <p>and then the output from <code>f()</code> looks like</p>
  <pre><code>             user            system           elapsed 
  129.599 (2.16min)  0.663 (663.00ms) 130.438 (2.17min) 
      wrote 447,337,021 bytes
                user             system            elapsed 
  2746.37 (45.77min)  145.299 (2.42min) 2896.68 (48.28min) 
              user           system          elapsed 
   9.544 (9.54sec) 0.755 (755.00ms)  10.3 (10.30sec) 
  </code></pre>
  <p>and it takes some time to figure out the correspondence between functions and timings.</p>
  <p>I tried this function:</p>
  <pre><code>verbose &lt;- function (expr) {
    ret &lt;- system.time(expr)
    cat(&quot;&lt;&lt;&lt;&lt;&lt;&lt;&quot;)
    print(expr)
    print(ret)
  }
  &gt; verbose(Sys.sleep(2))
  &lt;&lt;&lt;&lt;&lt;&lt;NULL
             user          system         elapsed 
       0 (0.00ms)      0 (0.00ms) 2.002 (2.00sec) 
  </code></pre>
  <p>Alas, it prints <code>NULL</code> instead of <code>Sys.sleep(2)</code> (i.e., the value instead of the expression).</p>
  <p>So, how do I save the <code>expr</code>'s printed representation in <code>verbose</code> for future output?</p>