14.4 Quiz questions

You can include one or more multiple-choice quiz questions within a tutorial to help verify that readers understand the concepts presented. Questions can either have a single or multiple correct answers.

Include a question by calling the question() function within an R code chunk, e.g.,

```{r letter-a, echo=FALSE}
question("What number is the letter A in the English alphabet?",
  answer("8"),
  answer("14"),
  answer("1", correct = TRUE),
  answer("23")
)
```

Figure 14.4 shows what the above question would look like within a tutorial.

A question in a tutorial.

FIGURE 14.4: A question in a tutorial.

The functions question() and answer() have several other arguments for more features that allow you to customize the questions and answers, such as custom error messages when the user’s answer is wrong, allowing users to retry a question, multiple-choice questions, and multiple questions in a group. See their help pages in R for more information.