title: How to use set.seed() globally in R Markdown?
body: <p>Can someone please provide a working example of how to use set.seed() globally in R Markdown?  I am aware of <a href="https://yihui.name/knitr/demo/cache/" rel="noreferrer">Yihui's documentation</a> based on <a href="https://github.com/yihui/knitr/issues/274" rel="noreferrer">this bug report</a>, but I get an error message when I put the suggested option in my setup chunk as <code>knitr::opts_chunk$set(cache.extra = rand_seed)</code>.  </p>
  
  <p>What am I missing?  I currently just have a random seed in the first code chunk that needs it, but later chunks should use the same seed.</p>
  
  <p>[UPDATE BELOW]</p>
  
  <p>My setup chunk:</p>
  
  <pre><code>```{r setup, include=FALSE}
  #knitr::opts_chunk$set(echo = TRUE)
  knitr::opts_knit$set(root.dir = "/Users/Zack/Documents/UCLA/Courses/PP290_NetworkScience")
  #library(knitr)
  knitr::opts_chunk$set(tidy.opts=list(width.cutoff=80),tidy=TRUE)
  knitr::opts_chunk$set(cache.extra = rand_seed)
  ```
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>Show in New WindowClear OutputExpand/Collapse Output
  Error in knitr::opts_chunk$set(cache.extra = rand_seed) : 
    object 'rand_seed' not found
  </code></pre>
  
  <p>The chunk that uses a seed is this:</p>
  
  <pre><code>```{r section1_3, error=TRUE, cache=FALSE, eval=TRUE, echo=TRUE}
  set.seed(01082017)
  # A binomial distribution is one that produces a series of numbers according to parameters you pass it.
  # We can easily make it produces 1s and 0s and then populate an adjacency matrix with them.
  # The last argument controls the ratio of 1s and 0s.  So, half the output will be 1, half will be 0, on average.
  rbinom(1,1,.5)
  rbinom(1,1,.5)
  rbinom(1,1,.5)
  rbinom(1,1,.5)
  rbinom(1,1,.5)
  ```
  </code></pre>
  
  <p>For now, I have removed <code>knitr::opts_chunk$set(cache.extra = rand_seed)</code> from my R Markdown file.</p>