-
Notifications
You must be signed in to change notification settings - Fork 3
/
HowToMarkdown.Rmd
228 lines (119 loc) · 3.85 KB
/
HowToMarkdown.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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
---
title: "A very short introduction to R Markdown"
author: "Lisa Dickel"
date: "2/12/2021"
output:
html_document: default
pdf_document: default
word_document: default
---
<br>
<br>
<br>
<br>
## 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 see <http://rmarkdown.rstudio.com>.
https://rmarkdown.rstudio.com/articles_intro.html
<br>
<br>
<br>
<br>
## Why is it useful
→ An "authoring framework" in which we can combine text and code
- Sharing analyses with other people - including code, output, and text
- No copying of code, output or plots
- No need for reader to have software installed which you used
- To create reproducible reports - change e.g. the data and reproduce the report!
- Communicate our findings in a readable, well formatted way
<br>
<br>
<br>
<br>
# How does it work
- Code chunks
- Text and headlines
- Output options: (html, word, pdf)
- You can also do small modifications and produce presentations, ebooks..
- Where does the output get saved → in your working directory!
- If you change something and knit again - it will be updated and overwritten
<br>
<br>
<br>
<br>
# Getting started
- install.packages("rmarkdown")
- Info about installation and really everything else: The definitive guide to RMarkdown!
![](https://www.math.ntnu.no/emner/ST2304/2021v/Week05/cover.png)
https://bookdown.org/yihui/rmarkdown/installation.html
- Set up a new file: File → New File → RMarkdown → choose which type of document you prefer!
- Knit: click on the 'knit' icon
- If you produce pdf output needs latex installed (e.g. tinytex does the job already and can be installed from R console)
- Knit to another format than specified in the header: dropdown menu beside 'knit' icon
- Boring to install Latex? → export as html and print to pdf in your web browser (e.g. easy to do in chrome)
<br>
<br>
<br>
<br>
## Including code and plots
You can also embed plots, for example:
```{r, echo=FALSE}
DragonFire <- read.csv(file="https://www.math.ntnu.no/emner/ST2304/2021v/Week05/DragonFire.csv")
plot(DragonFire$Size, DragonFire$Distance, xlab="Length (m)", ylab="Distance (m)")
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
<br>
<br>
<br>
<br>
## We can also include the code and the plot
```{r}
DragonFire <- read.csv(file="https://www.math.ntnu.no/emner/ST2304/2021v/Week05/DragonFire.csv")
plot(DragonFire$Size, DragonFire$Distance, xlab="Length (m)", ylab="Distance (m)")
```
<br>
<br>
<br>
<br>
## And in some cases we want to see only the code
```{r, message=FALSE}
library(dplyr)
```
<br>
<br>
<br>
<br>
## Or we can just run the code and show nothing!
```{r, include=FALSE}
library(dplyr)
```
→ here I loaded a package, but noone can see it!
<br>
<br>
<br>
<br>
---
# Formatting the text (#)
## Headers of different levels (##)
### Determined by number of hashtags (###)
*italian* (*)
**and bold** (**)
<br>
<br>
<br>
<br>
# What can go wrong
- If there is a problem anywhere in your script or it is missing some information, it will not knit and give an error
- Everything needed in the script (data, functions, packages) need to be loaded in the same script!
- The error that will be displayed will not necessarily refer to the line in the R script but possibly to the log file in your working directory
- You can maybe not see that file in your working directory - you need change settings to enable 'show hidden files'
<br>
<br>
<br>
<br>
# Need more help with R, RStudio etc?
→ Soon, soon there will be an introductory course again!
https://innsida.ntnu.no/start/#/feed//3873e72f-79ec-3867-9651-61a52da11a98
<br>
<br>
<br>
<br>