title: Problems using caret objects while knitting in R studio
body: <p>So when I knit the following code in <code>Rmarkdown</code> I get a specific error:</p>
  
  <pre><code># Install caret.
  install.packages("caret", repos="http://cran.us.r-project.org", dependencies=TRUE)
  library(caret)
  
  cross_val &lt;- caret::trainControl(method="repeatedcv", number=10, savePredictions=TRUE)
  
  fit1 &lt;- train(Class ~ Cl.thickness + Cell.size + Cell.shape + Marg.adhesion + 
                  Epith.c.size + Bare.nuclei + Bl.cromatin + Normal.nucleoli + Mitoses, 
                data = BreastCancer[complete.cases(BreastCancer),], 
                method = "glm", family="binomial", trControl = cross_val, 
                tuneLength = 5, control = list(20))
  </code></pre>
  
  <p>The error is:</p>
  
  <pre><code>Error in train.default(x, y, weights = w, ...) : object 'TrainControl' 
   not found Calls: &lt;Anonymous&gt; ... eval -&gt; train -&gt; train.formula -&gt; train -&gt; train.default
  </code></pre>
  
  <p>This is within RStudio, using R version 3.3.1 on 64-bit Windows 10. I've looked at some other posts and tried a few things with no changes thus far... <code>.libPaths()</code> gives me:</p>
  
  <pre><code>[1] "C:/Users/User Name/Documents/R/win-library/3.3"
  [2] "C:/Program Files/R/R-3.3.1/library
  </code></pre>
  
  <p><code>caret</code> is present in the <code>win-library/3.3</code> folder. I've tried resetting RStudio, unloading and reloading packages, updating packages, and reinstalling packages.</p>
  
  <p>When I run the code in the RStudio console I get no errors and it runs to completion and produces results correctly. However, if I run the code in the console and then run the <code>Rmarkdown</code> code again, I get a different error:</p>
  
  <pre><code>Error in library(caret) : there is no package called 'caret' Calls: 
   &lt;Anonymous&gt; ... withCallingHandlers -&gt; withVisible -&gt; eval -&gt; eval -&gt; 
   library Execution halted
  </code></pre>
  
  <p>I'm sort of at a dead end right now, so any hints/clues would be much appreciated! (Please let me know if more information would help!)</p>
  
  <p>EDIT 1:</p>
  
  <p>I should have noted that the error occurs regardless of whether I use <code>trainControl</code> or <code>caret::trainControl</code>.</p>