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

R Markdown

Communicate in a SMART way!

Invited Talk - R Ladies Abuja, Nigeria


Thiyanga S. Talagala

February 16, 2022

1 / 147

Packages

install.packages("rmarkdown")

install.packages("knitr")

2 / 147

Packages

install.packages("rmarkdown")

install.packages("knitr")

Additional packages

install.packages("tidyverse")

install.packages("reticulate")

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

Creating an R Markdown document

20 / 147
21 / 147
22 / 147
23 / 147
24 / 147
25 / 147

Select a folder to save the document

26 / 147

Give a name to the document

27 / 147
28 / 147
29 / 147
30 / 147

Demo

31 / 147
32 / 147

R Markdown pipeline

Image source: here

33 / 147
34 / 147

Customizing your R Markdown document: text

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

Change Header

Code

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

Output

Header 1

Header 2

Header 3

48 / 147

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 / 147

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 / 147

Include R codes

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

Anatomy of R Markdown

59 / 147

Anatomy of R Markdown

code chunk

60 / 147
61 / 147

Anatomy of R Markdown

Text

62 / 147
63 / 147

Anatomy of R Markdown

YAML

HTML Document

64 / 147
65 / 147

Anatomy of R Markdown

YAML

PDF Document

66 / 147
67 / 147
68 / 147

Anatomy of R Markdown

YAML

Word Document

69 / 147
70 / 147
71 / 147

Chunk options

72 / 147

fig.width/ fig.height

73 / 147

fig.width/ fig.height

74 / 147

echo [TRUE/ FALSE]

75 / 147

eval [TRUE/ FALSE]

76 / 147

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 / 147

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 / 147

Mathematical Equations

78 / 147

How to type Greek letters?

Please read my blog post here:

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

79 / 147

Styling your R Markdown document

YAML

80 / 147

toc: true

81 / 147

toc_float: true

82 / 147
83 / 147
84 / 147
85 / 147

number_sections

86 / 147
87 / 147
88 / 147

Styling your R Markdown document

theme

89 / 147
90 / 147
91 / 147
92 / 147
93 / 147

Styling your R Markdown document

highlight

94 / 147
95 / 147
96 / 147

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 / 147

Styling your R Markdown document

Tabbed Sections

98 / 147
99 / 147
100 / 147

R Markdown to R script

101 / 147
102 / 147
103 / 147
104 / 147
105 / 147

R script to R Markdown

Method 1 (Using Rstudio)

106 / 147
107 / 147
108 / 147
109 / 147
110 / 147
111 / 147

R script to R Markdown

Method 2 (Using R console)

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

Document your Analysis

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

Include Latex tables

120 / 147
121 / 147
122 / 147

Include images

123 / 147
124 / 147
125 / 147
126 / 147

Python and R together

install.packages("reticulate")

127 / 147
128 / 147
129 / 147
130 / 147

Parameterized R Markdown

131 / 147
132 / 147
133 / 147
134 / 147
135 / 147
136 / 147
137 / 147
138 / 147
139 / 147
140 / 147
141 / 147
142 / 147
143 / 147
144 / 147
145 / 147

Acknowledgements:

Yihui Xie, RStudio

Emi Tanaka, Monash University, Australia

All contributors

146 / 147

Thank you

Make some VOICE using R Makrkdown!

Slides are available at https://thiyanga.netlify.app/talk/nigeria/

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

147 / 147

Packages

install.packages("rmarkdown")

install.packages("knitr")

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