I have coded algorithms in R (Markdown) that take quite a long time to run to completion. I run the code and make sure it works before I knit the PDF, however when all the code is satisfactory, I then proceed to knit the PDF output and thus the code has to run again when generating the PDF, which doubles the run time - run once when checking and then run the code again when generating the PDF.
My Question:
How do I knit a PDF in Markdown without having to re-run all my code?
This is especially frustrating if there is a spelling error or notation I have to correct.
I bet most people are looking for a way to show the answer to the code but without re-running the code. If it is your case, this works like a charm:
cache = TRUE
The way to implement it:
```{r, cache = TRUE}
#your code
```
Advanced Usage:
The way to undo it is as simple as
cache = FALSE
If you want to make a new execution and store it on cache you must need cache = TRUE. You will see that the result will be always same, so, in order to undo it even a subtle change in the code will make the code re-run, just adding a space anywhere, an indent... will do the trick!
more information: cache for knitr
Attention! What this does is store in cache your current run, therefore, if you re-run your code the answer will be same, be careful where you use it, because it can lead to having always the same results if you forgot where you put it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With