Newer
Older
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
---
title: "Using RMarkdown"
teaching: 10
exercises: 2
questions:
- "How to write a lesson using RMarkdown?"
objectives:
- "Explain how to use RMarkdown with the new lesson template."
- "Demonstrate how to include pieces of code, figures, and challenges."
keypoints:
- "It shouldn't be difficult"
---
This episode demonstrates all the features that can be used when writing a
lesson in RMarkdown.
This first chunk is really important, and should be included in all markdown lessons.
The rest of the lesson should be written as a normal RMarkdown file. You can
include chunk for codes, just like you'd normally do:
Normal output:
~~~{.r}
1 + 1
~~~
{: .source}
~~~
[1] 2
~~~
{: .output}
Output with error message:
~~~{.r}
x[10]
~~~
{: .source}
~~~
Error in eval(expr, envir, enclos): object 'x' not found
~~~
{: .error}
Output generating figures:
~~~{.r}
library(ggplot2)
~~~
{: .source}
~~~
Warning: package 'ggplot2' was built under R version 3.1.3
~~~
{: .error}
~~~{.r}
ggplot(diamonds, aes(x = carat, y = price, color = cut)) +
geom_point()
~~~
{: .source}
<img src="../fig/swc-rmd-plot-example-1.png" title="plot of chunk plot-example" alt="plot of chunk plot-example" style="display: block; margin: auto;" />
For the challenges and their solutions, you need to pay attention to the where
the `>` go and where to leave blank lines. Otherwise, you can include chunks in
it to include instructions and solutions.
> ## Challenge: Can you do it?
>
> What is the output of this command?
>
>
> ~~~{.r}
> paste("This", "new", "template", "looks", "good")
> ~~~
> {: .source}
>
> > ## Solution
> >
> >
> > ~~~
> > [1] "This new template looks good"
> >
> > ~~~
> > {: .output}
> {: .solution}
{: .challenge}