title: Capture output of system command within a function in R
body: <p>I'm working with a function in a package that uses <code>system2()</code> to run a command within the function. This particular command prints some stuff to standard out. I want to capture the output of that <code>system2()</code> call, however <code>capture.output()</code> does not work. I understand how to run <code>system2()</code> directly and capture the standard output, but not how to get it in this specific situation.</p>
  
  <p>Simple example:</p>
  
  <pre><code>my_ls &lt;- function() {
    system2("ls")
    return("Hello")
  }
  my_ls()
  output &lt;- capture.output(my_ls())
  output
  </code></pre>