Lesson 14: Advanced Documentation
Lesson 14: Advanced DocumentationOverview
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.
Objectives
- 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
R
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 Markdown
14.1 - Why You Might Want to Use R MarkdownIn 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 Markdown
14.2 - Basic Features of R MarkdownHere 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 Markdown
14.3 - More Features in R MarkdownHere 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 Output
14.4 - R Markdown OutputAfter 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 Feature
14.5 - RStudio’s Project FeatureOnce 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 RNW
14.6 - Knit Together R and LaTeX with RNWI 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.