09 February 2018

R rmarkdown

R + Mark

Markdown

Markdown is intended to be as easy-to-read and easy-to-write as is feasible.

html

<a href="https://github.com/KevCaz/aboutRMarkdown">My repo</a>

markdown

[My repo](https://github.com/KevCaz/aboutRMarkdown)

Markdown

html

<ol>
  <li> items1 </li>
  <li> items2 </li>
  <li> items3 </li>
</ol>

markdown

1. items1
2. items2
3. items3

Markdown et al.

Markdown suffered from bad parenting

CommonMark

Markdown everywhere

Mail

R + markdown, how?

One package to rule them all

R package knitr

yaml

  • Wikipedia says: “YAML (YAML Ain’t Markup Language) is a human-readable data serialization language.
author: Bill June
data: 2018-11-03
  • metadata of your file

pandoc

So

  1. writing .Rmd document
  2. Click to obtain your final document (call render())
  3. knitr convert code chunk
  4. you obtain a .md version
  5. this .md file + yaml ==> pandoc

Dynamic document

Analysis

cos(pi)
R>> [1] -1
sin(3)
R>> [1] 0.14112
exp(10)
R>> [1] 22026.47

Figures

Table

head(CO2)
R>>   Plant   Type  Treatment conc uptake
R>> 1   Qn1 Quebec nonchilled   95   16.0
R>> 2   Qn1 Quebec nonchilled  175   30.4
R>> 3   Qn1 Quebec nonchilled  250   34.8
R>> 4   Qn1 Quebec nonchilled  350   37.2
R>> 5   Qn1 Quebec nonchilled  500   35.3
R>> 6   Qn1 Quebec nonchilled  675   39.2

Table

knitr::kable(head(CO2))
Plant Type Treatment conc uptake
Qn1 Quebec nonchilled 95 16.0
Qn1 Quebec nonchilled 175 30.4
Qn1 Quebec nonchilled 250 34.8
Qn1 Quebec nonchilled 350 37.2
Qn1 Quebec nonchilled 500 35.3
Qn1 Quebec nonchilled 675 39.2

Let’s practice

Open a Rmd file in Rstudio

What does it look like?

Render your document