title: How to fix Rmarkdown error "could not find the function". However notebook preview works
body: <p>So i prepared notebook in R and then knitted it to html. Everything was perfectly fine, but later on when i updated data, so i changed one line of code, i started to get error:</p>
  
  <pre><code>Error in ggplot(data = mydata, aes(x = fct_infreq(as.factor(worker)))): 
  could not find function "ggplot" Calls: &lt;Annonymous&gt; ... handle
   -&gt; withCallingHandlers -&gt; withvisible -&gt; eval -&gt;eval
  </code></pre>
  
  <p>However, when i coppied the whole script to the notebok and created a preview it works perfeclty well, and also when i run this ggplot function separately it works.</p>
  
  <pre><code>ggplot(data = mydata, aes(x = fct_infreq(as.factor(worker)))) +
    geom_bar(width = 0.5, color = "blue") +
    labs(x ="Worker", y = "Answers") +
    geom_text(stat ='count', aes(label = ..count.., vjust =-0.5)) +
    ggtitle("Total iterations")
  </code></pre>
  
  <p>The question is: why knitting to HTML doesnt work for me and what i am missing here</p>
  
  <p>thanks! </p>