learnr icon indicating copy to clipboard operation
learnr copied to clipboard

Add new anybox question type to solve #382

Open elmstedt opened this issue 5 years ago • 2 comments

Solves #382

This creates a question type which has multiple correct questions but for which it is not required to select all of the correct options before proceeding. A successfully answered question will add messages indicating which correct responses were missed as well as which incorrect responses were selected.

In order to pass the additional arguments min_right and max_wrong to question_anybox(), I added them as attributes to the question object returned by learnr::question(). This feels a bit kludgy, but I wanted to not alter the structure of the question object to avoid any potential conflicts. Giving the object two additional attributes seemed the least invasive.

---
title: "Tutorial"
output: learnr::tutorial
runtime: shiny_prerendered
---

```{r setup, include=FALSE}
library(learnr)
knitr::opts_chunk$set(echo = FALSE)
```

## Topic 1

```{r two_right_one_wrong, echo = FALSE}
question_anybox(
  "Select at least two toppings that belong on a Margherita Pizza (and no more than one that doesn't):",
  answer("tomato", correct = TRUE, message = "Tomatoes too!"),
  answer("mozzarella", correct = TRUE, message = "Don't forget the cheese!"),
  answer("basil", correct = TRUE, message = "Basil gives it a distinctive flavor!"),
  answer("extra virgin olive oil", correct = TRUE, message = "You need olive oil too!"),
  answer("pepperoni", message = "Pepperoni is a great topping! ... just not on a Margherita Pizza"),
  answer("onions", message = "Onions!? No and yuck!"),
  answer("bacon", message = "Bacon doesn't belong here!"),
  answer("spinach", message = "Spinach? With Olive Oil? Only if you're Popeye!"),
  random_answer_order = TRUE,
  allow_retry = TRUE,
  try_again = "Be sure to select all four toppings!",
  min_right = 2,
  max_wrong = 1
)
```

PR task list:

  • [X] Update NEWS
  • [X] Add tests (if possible)
  • [X] Update documentation with devtools::document()

elmstedt avatar Sep 25 '20 06:09 elmstedt

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

CLAassistant avatar Sep 25 '20 06:09 CLAassistant

I also don't know if this logic should be merged into the default checkbox logic, or if it should be made into a separate exported function.

schloerke avatar Sep 29 '20 20:09 schloerke