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

R Markdown

On your marks, get set, ready, go!


Thiyanga S. Talagala

December 28, 2020

1 / 143

Packages

install.packages("rmarkdown")

install.packages("knitr")

2 / 143

Packages

install.packages("rmarkdown")

install.packages("knitr")

Additional packages

install.packages("tidyverse")

install.packages("reticulate")

2 / 143
3 / 143
4 / 143
5 / 143
6 / 143
7 / 143
8 / 143
9 / 143
10 / 143
11 / 143
12 / 143
13 / 143
14 / 143
15 / 143
16 / 143
17 / 143
18 / 143
19 / 143

Creating an R Markdown document

20 / 143
21 / 143
22 / 143
23 / 143
24 / 143
25 / 143

Select a folder to save the document

26 / 143

Give a name to the document

27 / 143
28 / 143
29 / 143
30 / 143

Demo

31 / 143
32 / 143

R Markdown pipeline

Image source: here

33 / 143
34 / 143

Customizing your R Markdown document: text

35 / 143
36 / 143
37 / 143
38 / 143
39 / 143
40 / 143
41 / 143
42 / 143
43 / 143
44 / 143
45 / 143
46 / 143
47 / 143

Change Header

Code

# Header 1
## Header 2
### Header 3

Output

Header 1

Header 2

Header 3

48 / 143

Add content

Code

# Header 1
This is section 1.
## Header 2
This is section 1.2
### Header 3
This is section 1.2.1

Output

Header 1

This is section 1.

Header 2

This is section 1.2

Header 3

This is section 1.2.1

49 / 143

Text formatting

Code

text

Output

M1: This text is in italics.

M2: This is also italics.

M3: This text is in bold.

M4: This is also bold.

This text is strikethrough.

50 / 143

Include R codes

51 / 143
52 / 143
53 / 143
54 / 143
55 / 143
56 / 143
57 / 143
58 / 143

Anatomy of R Markdown

59 / 143

Anatomy of R Markdown

code chunk

60 / 143
61 / 143

Anatomy of R Markdown

Text

62 / 143
63 / 143

Anatomy of R Markdown

YAML

HTML Document

64 / 143
65 / 143

Anatomy of R Markdown

YAML

PDF Document

66 / 143
67 / 143
68 / 143

Anatomy of R Markdown

YAML

Word Document

69 / 143
70 / 143
71 / 143

Chunk options

72 / 143

fig.width/ fig.height

73 / 143

fig.width/ fig.height

74 / 143

echo [TRUE/ FALSE]

75 / 143

eval [TRUE/ FALSE]

76 / 143

Chunk options

  • eval = FALSE - prevent the code from being evaluated

  • include = FALSE - run the code but doesn't show it in the final document

  • echo = FALSE - prevent the code but not the results from appearing

  • message = FALSE - prevent messages from appearing in the finished file

  • results = "hide" - hide the printed output

  • error = TRUE - cause the render to continue even if the code returns an error

  • comment=NA - remove # from the output

77 / 143

Chunk options

  • eval = FALSE - prevent the code from being evaluated

  • include = FALSE - run the code but doesn't show it in the final document

  • echo = FALSE - prevent the code but not the results from appearing

  • message = FALSE - prevent messages from appearing in the finished file

  • results = "hide" - hide the printed output

  • error = TRUE - cause the render to continue even if the code returns an error

  • comment=NA - remove # from the output

Without comment=NA

a <- 1:5; a
## [1] 1 2 3 4 5

With comment=NA

a <- 1:5; a
[1] 1 2 3 4 5
77 / 143

Mathematical Equations

78 / 143

How to type Greek letters?

Please read my blog post here:

https://thiyanga.netlify.app/post/greekletters/

79 / 143

Styling your R Markdown document

YAML

80 / 143

toc: true

81 / 143

toc_float: true

82 / 143
83 / 143
84 / 143
85 / 143

number_sections

86 / 143
87 / 143
88 / 143

Styling your R Markdown document

theme

89 / 143
90 / 143
91 / 143
92 / 143
93 / 143

Styling your R Markdown document

highlight

94 / 143
95 / 143
96 / 143

Themes

  • default

  • cerulean

  • journal

  • flatly

  • darkly

  • readable

  • spacelab

  • united

  • cosmo

  • lumen

  • paper

  • sandstone

  • simplex

  • yeti

Highlight

  • default

  • tango

  • espresso

  • zenburn

  • haddock

  • breezedark

  • kate

  • monochrome

97 / 143

Styling your R Markdown document

Tabbed Sections

98 / 143
99 / 143
100 / 143

R Markdown to R script

101 / 143
102 / 143
103 / 143
104 / 143
105 / 143

R script to R Markdown

Method 1 (Using Rstudio)

106 / 143
107 / 143
108 / 143
109 / 143
110 / 143
111 / 143

R script to R Markdown

Method 2 (Using R console)

rmarkdown::render('11-Demo.R')
112 / 143

Document your Analysis

113 / 143
114 / 143
115 / 143
116 / 143
117 / 143
118 / 143
119 / 143

Include Latex tables

120 / 143
121 / 143
122 / 143

Include images

123 / 143
124 / 143
125 / 143
126 / 143

Python and R together

install.packages("reticulate")

127 / 143
128 / 143
129 / 143
130 / 143

Parameterized R Markdown

131 / 143
132 / 143
133 / 143
134 / 143
135 / 143
136 / 143
137 / 143
138 / 143
139 / 143
140 / 143
141 / 143

Acknowledgements:

Yihui Xie, RStudio

Emi Tanaka, Monash University, Australia

All contributors

142 / 143

Thank you

Make some VOICE using R Makrkdown!

Slides are available at https://talks-thiyanga.netlify.app/rmarkdown_rladies/rmarkdownrladies_tst#1

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

143 / 143

Packages

install.packages("rmarkdown")

install.packages("knitr")

2 / 143
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