title: Include code from an external R script, run in, display both code and output
body: <p>Is it possible to include code from an external R script in an .Rmd and simultaneously run the code, display the code, and display its results in the output .HTML file? For example, if I have </p>
  
  <pre><code>x &lt;- 1
  y &lt;- 3
  z &lt;- x + y
  z
  </code></pre>
  
  <p>in <code>external.R</code>. In the output document I want to see the code above along with the result of <code>z</code>, i.e. 4. Essentially, I want the equivalent of what would happen if I copy/pasted what's above in an R chunk. So I want</p>
  
  <pre><code>```{r}
  some.library::some.function("external.R")
  ```
  </code></pre>
  
  <p>to be the equivalent of</p>
  
  <pre><code>```{r}
  x &lt;- 1
  y &lt;- 3
  z &lt;- x + y
  z
  ```
  </code></pre>
  
  <p>In the output HTML file.
  I've tried things like <code>knitr::read_chunk('external.R)</code> and <code>source('external.R</code>)`, but these don't display the code. Am I missing something simple?</p>
  
  <hr>
  
  <p><strong>EDIT</strong></p>
  
  <p>I found that <code>source('external.R', echo = TRUE)</code> will produce what I ask, but each line of the output's displayed code/results is prepended by <code>##</code>. Any way to make it look like it would if the code was simply copy/pasted in a chunk in the .Rmd?</p>