Lesson 14: Advanced DocumentationLesson 14: Advanced Documentation
The "spin" functionality in knitr for producing html from R script files (.R files) is very useful, and nearly perfrect for homework. But what do you do if you want to create more polished reports - say for you supervisor at work? Here we'll explore the "Rmarkdown" document language that is part of knitr.
- Create Rmarkdown documents and compile them using knitr
- Use chunk options to control size of figures and display of code
- Use the "projects" feature in RStudio to manage multiple porjects in R
- Create basic pdf files using LaTex with knitr
The R code file and data files for this lesson can be found on the Essential R - Notes on learning R page.
14.1 - Why You Might Want to Use R Markdown14.1 - Why You Might Want to Use R Markdown
In this video we'll explore some of the benefits of compiling documents from Rmarkdown vs from .R files. I hope to convince you that Rmarkdown is worth the extra complexity (which is minimal). You may also want to read this recent Introductory R blog, which gives another look at R markdown.
14.2 - Basic Features of R Markdown14.2 - Basic Features of R Markdown
Here we'll look at the basic construction of an Rmarkdown (.rmd) file - the big idea is that R code is contianed in "chunks" within a text document.
14.3 - More Features in R Markdown14.3 - More Features in R Markdown
Here we'll look in more detail at chunk options in Rmarkdown which control how code and the output of the code is evaluated and displayed. A full listing of chunk options can be found at the knitr website.
14.4 - R Markdown Output14.4 - R Markdown Output
After all this looking at how .rmd files are constructed, we'll look at output and see how it is improved over the output from .R files.
14.5 - RStudio’s Project Feature14.5 - RStudio’s Project Feature
Once you start using R you can quickly find it difficult to keep track of your Rmarkdown files (or .R files) and your workspaces, etc. RStudio has a nice "project" feature that makes it simple to save the state of your RStudio window and return to it later.
14.6 - Knit Together R and LaTeX with RNW14.6 - Knit Together R and LaTeX with RNW
I would be remiss if I didn't at least mention that knitr also makes it possible to combine LaTeX and R code using .rnw files. If you already use LaTeX this might interest you, or if you have other reasons to learn LaTeX. I honestly find that RMarkdown does everything I need (up to and including EssentialR", but your mileage may vary.