Exercise

Getting started

  • Create an *.Rmd for HTML.
  • Now change some configuration options: choose a theme and add a table of contents. For the latter, create some headings/sections and sub-sections so that you can see your configuration in action.

Adding code

  • Add a chunk that does the following statistical calculation. summary(mtcars)
  • Add a chunk that produces a visualization. If you need an example, create a density plot of the population total variable from the midwest data set in the ggplot2 package. Now align it with the fig.align chunk option.
  • Add a chunk similar to the previous but have the resulting document hide the code, just showing the visualization.
  • Now add a chunk that only shows the code, but doesn’t actually run it.
  • Add a chunk that creates an R object such as a set of numbers or text. Then use that object in the text via inline R code. For example, show only the first element of the object in a sentence.
  • Bonus: Set a chunk option that will be applied to the whole document. For example, make the default figure alignment be centered, or have the default be to hide the code.

Dealing with text

  • Italicize or bold some words.
  • Add a hyperlink.
  • Add a line break via HTML. Bonus: use htmltools and the br() function to add a line break within an R chunk. See what happens when you simply put several line returns.
  • Change your output to PDF.

More

For these, you’ll have to look it up, as I haven’t explicitly discussed it.

  • Create a quoted block.
  • Add a subtitle to your document
  • Remove the # from the R chunk outputs

Advanced

For this you’d have to know a little CSS, but just doing it once will go quite a ways to helping you feel comfortable being creative with your own CSS files.

  • Create a *.css file to set an option for your link color. Don’t forget to refer to it in your YAML configuration section of the Rmd file.
  • Create a special class of links and add a link of that class.