title: Proper R Markdown Code Organization
body: <p>I have been reading about R Markdown (<a href="http://eriqande.github.io/rep-res-web/lectures/learning-rmarkdown-in-an-hour.html" rel="nofollow noreferrer">here</a>, <a href="http://rmarkdown.rstudio.com/authoring_basics.html" rel="nofollow noreferrer">here</a>, and <a href="http://yihui.name/knitr/demo/externalization/" rel="nofollow noreferrer">here</a>)  and using it to create solid reports. I would like to try to use what little code I am running to do some ad hoc analyses and turn them into more scalable data reports. </p>
  
  <p>My question is rather broad: Is there a proper way to organize your code around an R Markdown project? Say, have one script that generates all of the data structures?</p>
  
  <p>For example: Let's say that I have the <code>cars</code> data set and I have brought in commercial data on the manufacturer. What if I wanted to attach the manufacturer to the current <code>cars</code> data set, and then produce a separate summary table for each company using a manipulated data set <code>cars.by.name</code> as well as plot a certain sample using <code>cars.import</code>?</p>
  
  <p><strong>EDIT:</strong> Right now I have two files open. One is an R Script file that has all of the data manipulation: subsetting and re-categorizing values. And the other is the R Markdown file where I am building out text to accompany the various tables and plots of interest. When I call an object from the R Script file--like:</p>
  
  <pre class="lang-r prettyprint-override"><code>```{r}
  table(cars.by.name$make)
  ```
  </code></pre>
  
  <p>I get an error saying <code>Error in summary(cars.by.name$make) : object 'cars.by.name' not found</code></p>
  
  <p><strong>EDIT 2:</strong> I found this older thread to be helpful. <a href="https://stackoverflow.com/questions/10966109/how-to-source-r-markdown-file-like-sourcemyfile-r">Link</a>
  </p>
  
  <pre><code>---
  title: "Untitled"
  author: "Jeb"
  date: "August 4, 2015"
  output: html_document
  ---
  
  
  This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see &lt;http://rmarkdown.rstudio.com&gt;.
  
  When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
  
  ```{r}
  table(cars.by.name$make)
  ```  
  
  ```{r}
  summary(cars)
  summary(cars.by.name)
  ```
  
  ```{r}
  table(cars.by.name)
  ```   
  You can also embed plots, for example:
  
  ```{r, echo=FALSE}
  plot(cars)
  plot(cars.import)
  ```
  
  Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
  </code></pre>