-
Notifications
You must be signed in to change notification settings - Fork 9
/
presentation.Rmd
210 lines (150 loc) · 6.76 KB
/
presentation.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
---
title: "Manuscripts in Rmarkdown"
subtitle: https://stirlingcodingclub.github.io/Manuscripts_in_Rmarkdown/
author: "Brad Duthie"
date: "08 February 2023"
output:
beamer_presentation:
theme: "default"
colortheme: "default"
fonttheme: "default"
ioslides_presentation: default
powerpoint_presentation: default
slidy_presentation: default
header-includes:
- \usepackage{hyperref}
colorlinks: true
linkcolor: blue
urlcolor: blue
bibliography: refs.bib
---
## Objectives for learning Rmarkdown
```{r, echo = FALSE}
library(knitr);
dat <- read.csv(file = "data/Bumpus_data.csv");
```
\begin{enumerate}
\setlength\itemsep{0.5em}
\item Understand the features of Rmarkdown and why using it to write scientific documents may be useful \pause
\item Create an Rmarkdown file and assemble it into an HTML, PDF, or DOCX document using knitr in Rstudio \pause
\item Apply basic integration of R code into Rmarkdown to analyse data and plot results in output \pause
\item Be able to navigate to the \href{https://stirlingcodingclub.github.io/Manuscripts_in_Rmarkdown/Rmarkdown_notes.html}{accompanying Rmarkdown notes} and make use of them for additional tools \pause
\item Continue asking questions and sharing tips in the Rmarkdown repository \href{https://github.com/StirlingCodingClub/Manuscripts_in_Rmarkdown/issues}{issues page} on GitHub
\end{enumerate}
## Where did Rmarkdown come from?
| Microsoft Word (1983) | \LaTeX (1980) |
| ------------------------------ | --------------------------------- |
| - Used in the life sciences | - Used in maths and physics |
| - What you see is what you get | - Edit files in [plain text](https://en.wikipedia.org/wiki/LaTeX) (code) |
| - Proprietary software | - Free software |
| - **Low learning curve** | - **High learning curve** |
| - **No analysis integration** | - **No analysis integration** |
<hr> \pause
**Rmarkdown** (2012) is free software with a **relatively low learning curve** in which authors write in plain text and can easily integrate R analyses, citations, and tables or figures.
## Sample writing in code with Rmarkdown
**From the Introduction:**
```
Bumpus published a paper and all of the data that he
had collected [@Bumpus1898]. These data are now a
classic data set in biology, and have been analysed
multiple times [e.g., @Johnston1972].
```
\vspace{4 mm}
\hrule
\vspace{4 mm}
\pause
Bumpus published a paper and all of the data that he
had collected [@Bumpus1898]. These data are now a
classic data set in biology, and have been analysed
multiple times [e.g., @Johnston1972].
## Sample writing in code with Rmarkdown
**From the Results:**
```{r, echo = FALSE}
res <- t.test(formula = dat$totlen ~ dat$surv, alternative = "less",
var.equal = TRUE); # Two sample t-test results
tval <- as.numeric(res$statistic); # Get the t-test statistic
pval <- res$p.value; # Get the p value from the t-test results
live <- as.numeric(res$estimate[1]); # Get mean length of living sparrows
dead <- as.numeric(res$estimate[2]); # Get mean length of dying sparrows
```
```
Bumpus' data included 'r sum(dat$surv == "alive")'
sparrows that lived and 'r sum(dat$surv == "dead")'
sparrows that died. The mean total length of living
sparrows was 'r round(live, digits = 2)' mm, and the
mean total length of dead sparrows was
'r round(dead, digits = 2)' mm.
```
\vspace{4 mm}
\hrule
\vspace{4 mm}
\pause
Bumpus' data included `r sum(dat$surv == "alive")`
sparrows that lived and `r sum(dat$surv == "dead")`
sparrows that died. The mean total length of living
sparrows was `r round(live, digits = 2)` mm, and the
mean total length of dead sparrows was
`r round(dead, digits = 2)` mm.
## Complex figures and tables directly in Rmarkdown
```{r, echo = FALSE}
kable(dat[1:12, 1:8]);
```
## Why is Rmarkdown worth learning?
\begin{enumerate}
\setlength\itemsep{0em}
\item Learning is a relatively low additional time investment if already invested in R \pause
\item Produces high quality \href{https://stirlingcodingclub.github.io/Manuscripts_in_Rmarkdown/ms_history/ms_final.html}{HTML}, \href{https://github.com/StirlingCodingClub/Manuscripts_in_Rmarkdown/blob/224e0f3673aece576d5c859f5409b6c9b68a5565/ms.pdf}{PDF}, and \href{https://github.com/StirlingCodingClub/Manuscripts_in_Rmarkdown/raw/224e0f3673aece576d5c859f5409b6c9b68a5565/ms.docx}{DOCX} documents with the push of a button from an \href{https://github.com/StirlingCodingClub/Manuscripts_in_Rmarkdown/blob/master/ms.Rmd}{Rmd file} in Rstudio \pause
\item Removes the need to format citations manually (with BibTeX) \pause
\item Allows users to insert images and equations seamlessly \pause
\item Can be used to write slide presentations (in PDF, HTML, PPTX, or Rshiny) \pause
\item \textbf{Complete integration of data analysis and manuscript} (no copy-pasting when values or figures change)
\end{enumerate}
\vspace{2mm}
\hrule
\pause
\vspace{2mm}
**You do not need to learn everything at once for Rmarkdown to be useful. If you get stuck or cannot figure out how to do something, you can just knit a DOCX and work from there.**
## Create a new Rmarkdown document {.smaller}
**In Rstudio**: <u>F</u>ile $\to$ New <u>F</u>ile $\to$ R <u>M</u>arkdown... \pause
```
---
title: "Untitled"
author: "Brad Duthie"
date: "17 November 2018"
output: html_document
---
## R Markdown
This is an R Markdown document. Markdown is a simple
formatting syntax for authoring HTML, PDF, and MS
Word documents. For more details on using R Markdown
```
## Copy and paste an abstract, then knit {.smaller}
```
---
title: "High sparrow body length decreases survival"
author: "Brad Duthie"
date: "17 November 2018"
output: html_document
---
Abstract
================================================
Writing documents in Rmarkdown using Rstudio can
make scientific workflow more efficient, and here
```
\pause
\vspace{2mm}
\hrule
\vspace{2mm}
**Now find the 'Knit' button on the toolbar**
![](images/Rstudio_toolbar.png)
## Notes and what to do next
Example [manuscript](https://github.com/StirlingCodingClub/Manuscripts_in_Rmarkdown/blob/master/ms.Rmd) available on GitHub, and how to write it to create a manuscript quality [PDF](https://github.com/StirlingCodingClub/Manuscripts_in_Rmarkdown/blob/b2445dcf69d7c0f9c1f118c1695009644f6aeee6/ms.pdf), [HTML](https://stirlingcodingclub.github.io/Manuscripts_in_Rmarkdown/ms_history/ms_results.html), or [DOCX](https://github.com/StirlingCodingClub/Manuscripts_in_Rmarkdown/raw/b2445dcf69d7c0f9c1f118c1695009644f6aeee6/ms.docx).
\vspace{4mm}
\hrule
\vspace{4mm}
**https://stirlingcodingclub.github.io/Manuscripts_in_Rmarkdown/Rmarkdown_notes.html**
\vspace{4mm}
\hrule
\vspace{4mm}
See the notes above for a full walkthrough on how to write a manuscript in Rmarkdown.
## Literature cited