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

R Markdown

Communicate in a SMART way!

Research Lounge Meet, University of Moratuwa


Dr. Thiyanga S. Talagala

October 18, 2022

1 / 128

Packages

install.packages("rmarkdown")

install.packages("knitr")

2 / 128

Packages

install.packages("rmarkdown")

install.packages("knitr")

Additional packages

install.packages("tidyverse")

install.packages("reticulate")

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

Creating an R Markdown document

20 / 128
21 / 128
22 / 128
23 / 128
24 / 128
25 / 128

Select a folder to save the document

26 / 128

Give a name to the document

27 / 128
28 / 128
29 / 128
30 / 128

Demo

31 / 128
32 / 128

R Markdown pipeline

Image source: here

33 / 128
34 / 128

Customizing your R Markdown document: text

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

Change Header

Code

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

Output

Header 1

Header 2

Header 3

48 / 128

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

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

Include R codes

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

Anatomy of R Markdown

59 / 128

Anatomy of R Markdown

code chunk

60 / 128
61 / 128

Anatomy of R Markdown

Text

62 / 128
63 / 128

Anatomy of R Markdown

YAML

HTML Document

64 / 128
65 / 128

Anatomy of R Markdown

YAML

PDF Document

66 / 128
67 / 128
68 / 128

Anatomy of R Markdown

YAML

Word Document

69 / 128
70 / 128
71 / 128

Chunk options

72 / 128

fig.width/ fig.height

73 / 128

fig.width/ fig.height

74 / 128

echo [TRUE/ FALSE]

75 / 128

eval [TRUE/ FALSE]

76 / 128

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

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

Mathematical Equations

78 / 128

How to type Greek letters?

Please read my blog post here:

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

79 / 128

Styling your R Markdown document

YAML

80 / 128

toc: true

81 / 128

toc_float: true

82 / 128
83 / 128
84 / 128
85 / 128

number_sections

86 / 128
87 / 128
88 / 128

Styling your R Markdown document

theme

89 / 128
90 / 128
91 / 128
92 / 128
93 / 128

Styling your R Markdown document

highlight

94 / 128
95 / 128
96 / 128

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

Styling your R Markdown document

Tabbed Sections

98 / 128
99 / 128
100 / 128

Include Latex tables

101 / 128
102 / 128
103 / 128

Include images

104 / 128
105 / 128
106 / 128
107 / 128

Python and R together

install.packages("reticulate")

108 / 128
109 / 128
110 / 128
111 / 128

Parameterized R Markdown

112 / 128
113 / 128
114 / 128
115 / 128
116 / 128
117 / 128
118 / 128
119 / 128
120 / 128
121 / 128
122 / 128
123 / 128
124 / 128
125 / 128
126 / 128

Acknowledgements:

Yihui Xie, RStudio

Emi Tanaka, Monash University, Australia

All contributors

127 / 128

Thank you

Make some VOICE using R Makrkdown!

Slides are available at https://hellormd.netlify.app/

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

128 / 128

Packages

install.packages("rmarkdown")

install.packages("knitr")

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