-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathtemplate.Rmd
More file actions
58 lines (40 loc) · 3.27 KB
/
template.Rmd
File metadata and controls
58 lines (40 loc) · 3.27 KB
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
---
title: "Assignment Template"
author: "Dr Thomas Robinson and Dr Dan de Kadt"
date: "AT 2023"
output: html_document
---
```{r setup, include=FALSE}
# this chunk contains code that sets global options for the entire .Rmd.
# we use include=FALSE to suppress it from the top of the document, but it will still appear in the appendix.
knitr::opts_chunk$set(echo = FALSE) # actually set the global chunk options.
# we set echo=FALSE to suppress code such that it by default does not appear throughout the document.
# note: this is different from .Rmd default
```
This document contains the necessary commands and layout to meet the formatting requirements for MY472. You should use the template.Rmd file as the basis for your own answers to the assigned exercises.
## Formatting requirements
* You must present all results in full sentences, as you would in a report or academic piece of writing
* If the exercise requires generating a table or figure, you should include at least one sentence introducing and explaining it. E.g. "The table below reports the counts of Wikipedia articles mentioning the LSE, by type of article."
* Unless stated otherwise, all code used to answer the exercises should be included as a code appendix at the end of the script. This formatting can be achieved by following the guidance in this template file.
* All code should be annotated with comments, to help the marker understand what you have done
* Your output should be replicable. Any result/table/figure that cannot be traced back to your code will not be marked
## Example of in-line figures without code
For those interested, we achieve the formatting requirements in two-steps: 1) in the `setup` chunk, we set `knitr::opts_chunk$set(echo = FALSE)` so that code is not included (echoed) by default in code chunks; 2) we add a specific chunk at the end of the file to collect and print *all* the code in the Rmarkdown file. Do not delete the final code chunk from the template!
For example, below we use a code chunk to generate random data and include a scatter plot in-line. The code used to generate this chart is only reported at the end of the document.
```{r plot_example}
set.seed(89) # set a seed for R's psuedo-randomiser, for replicability.
x <- rnorm(100) # randomly draw 100 obs from normal distribution, save as object
y <- rnorm(100)
plot(x,y) # two-way scatterplot using R's default plotting
```
In specific instances, however, you may be directed to report your code in-line (or you may want to do this to illustrate a specific point). In these cases, we can override the default behaviour by adding the chunk option `echo = TRUE` to a specific R chunk. When `echo=TRUE`, your code is presented in-line with any output displayed afterwards. The same code will also be included in the appendix at the bottom of the document (which is fine).
```{r echo_example, echo=TRUE}
# {[language] [chunk_name], [chunk_options]}
# here we use echo=TRUE to override our global options and make the chunk appear exactly here.
print("This code chunk is visible in this section.")
```
## Appendix: All code in this assignment
```{r ref.label=knitr::all_labels(), echo=TRUE, eval=FALSE}
# this chunk generates the complete code appendix.
# eval=FALSE tells R not to run (``evaluate'') the code here (it was already run before).
```