-
Notifications
You must be signed in to change notification settings - Fork 2
/
rmarkdown1.Rmd
125 lines (75 loc) · 3.84 KB
/
rmarkdown1.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
---
title: "Introduction to R Markdown"
description: |
An introduction to R using R Markdown aimed at secondary school students (age 11-16) and for complete novices.A complete lesson plan to introduce the R coding language using R Markdown to deliver instructions.
date: 2022-02-26
output:
distill::distill_article:
self_contained: false
---
<div class="contributor_org">
`r xfun::embed_file(here::here("rmarkdown1", "markdown1.Rmd"), text = "Download .Rmd here")`
`r xfun::embed_file(here::here("rmarkdown1", "markdown1.docx"), text = "Download word document here")`
`r xfun::embed_file(here::here("rmarkdown1", "markdown1.pdf"), text = "Download pdf here")`
</div>
<div style="text-align: center">
<img src="rmarkdown1/feedback_first_markdown2.jpg" width="600px" min-width="300px" max-width="300px" />
</div>
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
```
## Introduction to R Markdown
## Lesson Objectives
To become familiar with the layout of an R Markdown document
To practice typing in the code chunk
To produce an output file of my work using the 'knit' command
## Packages used in this lesson:
- `tidyverse`
## Success Criteria:
I can write my name on my R Markdown document
I can write in the code chunk
I can produce an output file of my work
## Keywords:
* R code chunk
* knit
## How to write your name on your R Markdown document
On line 3, replace where it says 'write your name here' with your full name. Make sure you don't delete or write over the speech marks.
Click on the 'knit' command at the top of the pane. After a short wait you will see the output file of your work. Can you see your name on the output file?
If you can see your name, close the output file by clicking on X.
If you cannot see your name, drag the output file to the side so that you can see what you wrote in the Markdown file. Check you typed your name correctly. Check that there are speech marks around your name. Knit your Markdown document again. Has your name been printed? If so, close the output file by clicking on X.
## Typing in the code chunk
When you write code in the code chunk, R will carry out the commands. Code chunks are named r chunk1, r chunk2 etc. You must write your code in the lines between the top row of ``` and the bottom row of ```.
We will tell R to do a calculation for us. Type 10 + 2 into the code chunk. Click on the little arrow on the right of the code chunk to tell R to carry out the command.
```{r chunk1}
```
Did R give you the correct answer?
Now you make up an addition sum and type it into code chunk2. Don't forget to click on the arrow on the right to run your code.
```{r chunk2}
```
Now click on knit. Read through your output file to check that your sums are printed.
## Extension
Try typing in some more calculations. Try a subtraction calculation or a multiplication calculation. (Use the symbol * for multiply). Type in code chunk3, chunk4 and chunk5 below.
```{r chunk3}
```
```{r chunk4}
```
```{r chunk5}
```
## Mystery code
I wonder what this code tells R to do.
Carefully copy and paste the following lines of code into code chunk 6. Run the code. What do you see?
x <- seq(1,128,1)
y <- sin((x / 128.0) * pi)
n <- 7
color <- rainbow(n, s = 1, v = 1, start = 0, end = max(1, n - 1)/n, alpha = 1)
plot(x, y, type="n", ylim = c(0,10))
for(i in 1:7) {lines(x, y+i, col=color[i], lwd = 15)}
```{r chunk6}
```
KNIT YOUR DOCUMENT for the final time. This will be the version of your work that your teacher will check.
Well done! You have completed your first R lesson.
## THE END
<div class="license">
**License and Citation:** You can use, modify, and adapt any of the lessons, but please include the following attribution: *RGirls Community. (2022, April 10). RGirls Lessons. Zenodo. [https://doi.org/10.5281/zenodo.6436861](https://doi.org/10.5281/zenodo.6436861)*
</div>