Lesson 14: Advanced Documentation

Lesson 14: Advanced Documentation

Overview

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

Upon completion of this lesson, you should be able to:

  • 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 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 Markdown

14.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 Markdown

14.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.

(NOTE! Some students have reported getting error messages when trying to use the "Knit HTML" button on the editor toolbar. If you are having problems check the CRAN mirror setting under Tools > Global Options (Mac: RSTudio > Preferences) - it should be set to a mirror that is closer to your location.

14.4 - R Markdown Output

14.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 Feature

14.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 RNW

14.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.


Legend
[1]Link
Has Tooltip/Popover
 Toggleable Visibility