title: Knitr: R package check error, object 'opts_chunk' not found
body: <p>I am getting the following error when checking my R package</p>
  
  <pre><code>&gt; Error: could not find function "locdata"
  &gt; Execution halted
  &gt; when running code in ‘DFSurvey.Rnw’
  &gt;   ...
  &gt; 
  &gt; &gt; opts_chunk$set(cache = TRUE, fig.path = "DFSurveyImages/", dev = "pdf")
  &gt; 
  &gt;   When sourcing ‘DFSurvey.R’:
  &gt; Error: object 'opts_chunk' not found
  &gt; Execution halted
  </code></pre>
  
  <p>Yihui Xie (knitr developer) said that was because in RStudio, knitr was not set as the method for weaving .Rnw files, <a href="https://groups.google.com/forum/?fromgroups#!topic/knitr/9672CBbc8CM">https://groups.google.com/forum/?fromgroups#!topic/knitr/9672CBbc8CM</a>.  I have knitr set in both the tools and build options, in the R package DESCRIPTION file I have:</p>
  
  <pre><code>VignetteBuilder: knitr
  Suggests: knitr
  </code></pre>
  
  <p>and in the vignette I have:</p>
  
  <pre><code>%\VignetteEngine{knitr}
  %\VignetteDepends{knitr,xtable,TSP}
  </code></pre>
  
  <p>When I use compile the pdf in RStudio or use knit("KNITR.Rnw"), it compiles correctly.  When I check the package, I get the above errors for each vignette.  I even put </p>
  
  <pre><code>require(knitr)
  </code></pre>
  
  <p>before my opts_chunk$set statement. That did not help.  I have also run the check from the command line and gotten the same error.  Thank you for any help.</p>
  
  <p>Knitr is a useful package.  I run long simulations in vignettes, and the cache makes it possible to correct errors without running the simulations over each time.  It does not have the problem of trying to find the Sweave.sty file either.</p>
  
  <p>Here is my <code>sessionInfo()</code></p>
  
  <pre><code>&gt; R version 3.0.0 (2013-04-03)
  &gt; Platform: x86_64-apple-darwin10.8.0 (64-bit)
  &gt; 
  &gt; locale:
  &gt; [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
  &gt; 
  &gt; attached base packages:
  &gt; [1] tcltk     grid      stats     graphics  grDevices utils     datasets  methods  
  &gt; [9] base     
  &gt; 
  &gt; other attached packages:
  &gt;  [1] DualFrame_0.5         xtable_1.7-1          TSP_1.0-7            
  &gt;  [4] maptools_0.8-23       lattice_0.20-15       foreign_0.8-53       
  &gt;  [7] spsurvey_2.5          sp_1.0-9              stringr_0.6.2        
  &gt; [10] sqldf_0.4-6.4         RSQLite.extfuns_0.0.1 chron_2.3-43         
  &gt; [13] gsubfn_0.6-5          proto_0.3-10          RSQLite_0.11.3       
  &gt; [16] DBI_0.2-7             knitr_1.2             gpclib_1.5-5         
  &gt; 
  &gt; loaded via a namespace (and not attached):
  &gt; [1] deldir_0.0-22  digest_0.6.3   evaluate_0.4.3 formatR_0.7    MASS_7.3-26   
  &gt; [6] rgeos_0.2-17   tools_3.0.0   
  </code></pre>