-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparsons.Rmd
163 lines (128 loc) · 3.35 KB
/
parsons.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
---
title: "Parsons"
output: learnr::tutorial
runtime: shiny_prerendered
---
```{r setup, include=FALSE}
library(learnr)
library(parsons)
library(gsheet)
library(dplyr)
library(ggplot2)
knitr::opts_chunk$set(echo = FALSE)
```
## Creating a parsons question
### Using pass and fail conditions
An alternative way to specify the correct answer(s) is to supply a pass_if() statment. Using `pass_if` and `fail_if` is a powerful way to provide feedback to your students.
These `pass_if` and `fail_if` statements are evaluated in turn, until the first expectation evaluates to `TRUE`, and the `learnr` will provide the feedback in the `message`.
You can specify `pass_if()` as well as `fail_if()` in any of the following ways:
- A character vector, that must be matched exatcly, or
- A function in the tradition form `function(x)...`, e.g. `function(x) length(x) <3`
- A function specified using the `rlang` tidy evaluation formula notation, e.g. `~length(.) < 3`
### Features
- For tidyverse problem_type, items (except the last) in the right hand column will have a %>% appended, and for ggplot2 every line will be followed by a +.
- The initial values are shuffled into random answer order.
### Limitations
- it does not do any code evaluation
- it does not support identation
- it assumes code is from the tidyverse and only supports the magrittr pipe ( %>% ) operator
## Quiz 1
**What are the top 5 Sub.Category measured by sum profit?**
```{r}
retail <- read.csv("data_input/retail.csv")
```
Try to execute your solution here:
```{r addition, exercise=TRUE, exercise.eval = TRUE}
head(retail)
```
```{r quiz1}
question_parsons(
initial = c(
"Accessories",
"Copiers",
"Binders",
"Phones",
"Paper"
),
answer(
c(
"Copiers",
"Phones",
"Accessories",
"Paper",
"Binders"
),
correct = TRUE
),
fail_if(
~ length(.) < 5,
"Provide more answer"
),
submit_button = "submit answer"
)
```
## Quiz 2
*Which category product makes up our high-value profit*
```{r quiz2}
question_parsons(
initial = c(
"group_by(Category)",
"retail",
"arrange(desc(total_profit))",
"summarise(total_profit = sum(Profit))"
),
answer(
c(
"retail",
"group_by(Category)",
"summarise(total_profit = sum(Profit))",
"arrange(desc(total_profit))"
),
correct = TRUE
),
fail_if(
~ length(.) < 4,
"Provide more answer"
),
fail_if(
~{.[1] != "retail"},
message = "your solution should start with 'retail'"
),
fail_if(
~{.[2] != "group_by(Category"},
message = "you need to group_by first, before summarise"
)
,
submit_button = "submit answer",
problem_type = "tidyverse",
allow_retry = TRUE
)
```
## Quiz 3
How to create this plot? (use `retail2` dataset)
```{r}
retail2 <- retail[1:100,]
ggplot(retail2,aes(x = Category, y = Sales)) +
geom_boxplot() + geom_jitter()
```
Try to execute your solution here:
```{r addition2, exercise=TRUE, exercise.eval = TRUE}
retail2 <- retail[1:100,]
```
```{r quiz}
question_parsons(
initial = c(
"geom_boxplot()",
"geom_jitter() ",
"ggplot(retail2,aes(x = Category, y = Sales))"
),
pass_if(
c(
"ggplot(retail2,aes(x = Category, y = Sales))",
"geom_boxplot()",
"geom_jitter() "
)
),submit_button = "submit answer",
problem_type = "ggplot2"
)
```