R markdown is a very convenient and useful tool for communicating R output. It allows us to write text directly into a file, which will then be rendered into a presentable format, and it also allows us to embed R code into our document, which will be processed when we “knit” the document, with the results presented in the “knitted” output.
We have used R markdown files extensively in the course so far, so hopefully the format is now familiar to you. If you need a refresher on the basics of R markdown, this cheat sheet from R studio is very helpful. I suggest you download it and keep it open on your desktop while completing your homeworks.
I want to emphasise to all of you that the purpose of R markdown is to communicate results. It is not intended to experiment with code or to run very long and complex models. That is what R scripts are for. You should limit your code in R markdown to what is necessary for communication. In the case of your homeworks, you need to communicate:
To do this, you do not necessarily need to produce the results from the code inside the R markdown file. Instead:
saveRDS()
function.readRDS()
function inside a code chunk.eval = FALSE
option to the
brackets above that chunk.You do not need to do this for every line of code, and most code is fine to run inside R markdown. You should use your own judgement though to determine which code it is foolish to run inside R markdown: very intensive machine learning algorithms will certainly fall into this category.
In general, I recommend you:
saveRDS()
.eval = FALSE
option for those chunks which contain
computationally intensive algorithms, and instead using
readRDS()
in a separate chunk to read in the object which
you already created.