title: Making knitr run a r script: do I use read_chunk or source?
body: <p>I am running R version 2.15.3 with RStudio version 0.97.312. I have one script that reads my data from various sources and creates several data.tables. I then have another r script which uses the data.tables created in the first script. I wanted to turn the second script into a R markdown script so that the results of analysis can be outputted as a report. </p>
  
  <p>I do not know the purpose of <code>read_chunk</code>, as opposed to <code>source</code>. My <code>read_chunk</code> is not working, but <code>source</code> is working. With either instance I do not get to see the objects in my workspace panel of RStudio. </p>
  
  <p>Please explain the difference between <code>read_chunk</code> and <code>source</code>? Why would I use one or the other? Why will my .Rmd script not work</p>
  
  <h2>Here is ridiculously simplified sample</h2>
  
  <p>It does not work. I get the following message </p>
  
  <blockquote>
    <p>Error: object 'z' not found  </p>
  </blockquote>
  
  <p>Two simple files...</p>
  
  <p>test of source to rmd.R</p>
  
  <pre><code>x &lt;- 1:10
  y &lt;- 3:4
  z &lt;- x*y  
  </code></pre>
  
  <p>testing source.Rmd</p>
  
  <pre><code>Can I run another script from Rmd
  ========================================================
  
  Testing if I can run "test of source to rmd.R"
  
  ```{r first part}
  require(knitr)
  read_chunk("test of source to rmd.R")
  a &lt;- z-1000
  a
  ```
  
  The above worked only if I replaced "read_chunk" with "source". I 
  can use the vectors outside of the code chunk as in inline usage. 
  So here I will tell you that the first number is `r a[1]`. The most 
  interesting thing is that I cannot see the variables in RStudio 
  workspace but it must be there somewhere.
  </code></pre>