+ - 0:00:00
Notes for current slide
Notes for next slide

Microbes on Earth





R session 04 - R markdown

Daniel Vaulot

2021-10-12

1 / 32

Outline



  • What is Markown ?
  • Rmarkdown syntax
  • R chunks
  • Some applications
2 / 32

What is markdown ?

  • Created in 2004 by John Gruber and Aaron Swartz

  • Goal : "to write using an easy-to-read and easy-to-write plain text format, optionally convert it to structurally valid HTML".

3 / 32

What is markdown ?

  • Created in 2004 by John Gruber and Aaron Swartz

  • Goal : "to write using an easy-to-read and easy-to-write plain text format, optionally convert it to structurally valid HTML".

Many flavors...

  • MultiMarkdown
  • GitHub Flavored Markdown (GFM)
  • Pandoc
  • CommonMark
3 / 32

Rmarkdown

Mix

  • Markdown

    • paragraph structure
    • comments
    • links
  • R code ("chunks")

  • Output of R code

4 / 32

Your first Rmarkdown file

Who has not been able to install Rmarkdown and Latex ?

5 / 32

Your first Rmarkdown file

Who has not been able to install Rmarkdown and Latex ?

5 / 32

Your first Rmarkdown file

6 / 32

Your first Rmarkdown file

Knit to HTML

Save to "xxx.Rmd"

7 / 32

Your first Rmarkdown file

8 / 32

Your first Rmarkdown file

Knit of pdf

9 / 32

Your first Rmarkdown file

10 / 32

Markdown syntax

Headings

# Heading - level 1
## Heading - level 2
11 / 32

Markdown syntax

Headings

# Heading - level 1
## Heading - level 2

Heading - level 1

Heading - level 2

11 / 32

Markdown syntax

Paragraphs

Paragraphs are separated
by a blank line.
Two spaces at the end of a line
produces a line break.
12 / 32

Markdown syntax

Paragraphs

Paragraphs are separated
by a blank line.
Two spaces at the end of a line
produces a line break.

Paragraphs are separated by a blank line.

Two spaces at the end of a line
produces a line break.

12 / 32

Markdown syntax

Formatting

_italic_, *italic*, **bold**, `monospace`.
13 / 32

Markdown syntax

Formatting

_italic_, *italic*, **bold**, `monospace`.

italic, italic, bold, monospace.

Do not mix straight and backward quotes

13 / 32

Markdown syntax

Bullet lists

Bullet list:
* apples
* oranges
* pears
* passe crassane (4 spaces to indent)
14 / 32

Markdown syntax

Bullet lists

Bullet list:
* apples
* oranges
* pears
* passe crassane (4 spaces to indent)
  • apples
  • oranges
  • pears
    • passe crassane
14 / 32

Markdown syntax

Numbered lists

Numbered list:
1. wash
1. rinse
1. repeat
15 / 32

Markdown syntax

Numbered lists

Numbered list:
1. wash
1. rinse
1. repeat
  1. wash
  2. rinse
  3. repeat
15 / 32

Markdown syntax

[Text of the link](URL of the link)
# Example
[Markdown syntax](https://www.markdownguide.org/basic-syntax/)
16 / 32

Markdown syntax

[Text of the link](URL of the link)
# Example
[Markdown syntax](https://www.markdownguide.org/basic-syntax/)

Markdown syntax

16 / 32

Markdown syntax

Images

![Image name](URL of the link - can also be a local file on your computer)
# Example
![](https://i.pinimg.com/originals/1c/b7/24/1cb724b545de717ed0430e9d46e78eea.jpg)
17 / 32

Markdown syntax

Images

![Image name](URL of the link - can also be a local file on your computer)
# Example
![](https://i.pinimg.com/originals/1c/b7/24/1cb724b545de717ed0430e9d46e78eea.jpg)

17 / 32

Markdown syntax

Tables

ID | First | Last
--- | --- | ---
1 | Joe | Biden
18 / 32

Markdown syntax

Tables

ID | First | Last
--- | --- | ---
1 | Joe | Biden
ID First Last
1 Joe Biden
18 / 32

Rmarkdown conversion

19 / 32

Rmarkdown conversion

  • knitr : R library

  • Pandoc : command line tool

    • Converts from md to pdf, html, docx...
# HTML
> pandoc test1.md -f markdown -t html -s -o test1.html
# pdf
> pandoc test1.md -s -o test1.pdf

19 / 32

The Rmarkdown file

File structure

20 / 32

The Rmarkdown file

Knit process

21 / 32

The Rmarkdown file

Output

22 / 32

R Chunks

Insert R chunk

23 / 32

R Chunks

Run R chunk

  • Two options

24 / 32

R Chunks

Option 1: Run R chunk inside Rmd file

  • Use when building and debugging an Rmd file

25 / 32

R Chunks

Option 2: Knit R chunk to HTML

  • Use for final production

26 / 32

What can you do with Rmarkdown ?

Document your data analyses

  • If the data changes, you can re-run analysis in a matter of minutes
  • More and more journal request analyses scripts
27 / 32

What can you do with Rmarkdown ?

Presentation

28 / 32

What can you do with Rmarkdown ?

Posters

29 / 32

What can you do with Rmarkdown ?

Curriculum vitae

30 / 32

What can you do with Rmarkdown ?

Website

31 / 32

What did you learn ?




  • Rmarkdown: mix text, R chunk, R output
32 / 32

What did you learn ?




  • Rmarkdown: mix text, R chunk, R output
  • Compile to HTML or to PDF
32 / 32

What did you learn ?




  • Rmarkdown: mix text, R chunk, R output
  • Compile to HTML or to PDF
  • Can be used for many different purposes
32 / 32

What did you learn ?




  • Rmarkdown: mix text, R chunk, R output
  • Compile to HTML or to PDF
  • Can be used for many different purposes
  • Use to document your analysis process (for papers...)
32 / 32

Outline



  • What is Markown ?
  • Rmarkdown syntax
  • R chunks
  • Some applications
2 / 32
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow