May 7, 2015


Installing Rmarkdown


What is R Markdown?

  • Markdown file with embedded R code chunks.
    • Markdown: text-to-HTML conversion tool for web writers.
      • Allows you to write using an easy-to-read, easy-to-write plain text format.
  • Rmd -> md -> html (docx, pdf)
  • Can include both text and code to execute

Why R Markdown?

A convenient tool for reproducible and dynamic reports with R!

  • Execute code with the knitr.
  • Easy to learn syntax

Use it to consolidate your code and document into a single file:

  • Slideshows, pdfs, html documents, word files

Easy to use with version control: Use with GitHub

Simple Workflow

How to Open an Rmd File

Choose Output

YAML: A set of key value pairs at the start of your file. Begin and end the header with a line of three dashes (- - -)

R Studio template writes the YAML header for you

output: html_document
output: pdf_document
output: word_document
output: beamer_presentation (beamer slideshow - pdf)
output: ioslides_presentation (ioslides presentation - html)

Markdown basics

Markdown is a simple formatting language that is easy to use

  • Create lists with * or + sign
    • like this
    • and this
  • Use one or two asterisk marks to provide emphasis such as *italics* and **bold**. Can even include tables:
First Header Second Header
Content Cell Content Cell
Content Cell Content Cell

Markdown basics

R Code Chunks

Code blocks display with fixed-width font
#quick summary
## [1] 326
## [1] 3932.8
## [1] 18823

R Code Chunks

x <- sample(1:100, 5)
## [1] 90 94 19 49 48
  • You can name the code chunk.

  • echo = TRUE: The code will be displayed.

  • eval = TRUE: Yes, execute the code.

R Code Chunk Arguments

R Code Chunks: Displaying Plots