Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new anybox question type to solve #382 #434

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

elmstedt
Copy link

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:

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

@CLAassistant
Copy link

CLAassistant commented Sep 25, 2020

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.

Comment on lines +48 to +56
structure(learnr::question(
text = text,
...,
type = "learnr_anybox",
correct = correct,
incorrect = incorrect,
allow_retry = allow_retry,
random_answer_order = random_answer_order
), min_right = min_right, max_wrong = max_wrong)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add min_right and max_wrong to the options param in learnr::question

min_right = 1,
max_wrong = 0
) {
structure(learnr::question(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not namespace the functions using learnr:: within the learnr package

Comment on lines +85 to +86
min_right <- max(attr(question, "min_right"), 1)
max_wrong <- max(attr(question, "max_wrong"), 0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will then retrieve these from question$options

Comment on lines +87 to +94
ans <- question[["answers"]]
anss <- vapply(ans, `[[`, character(1), "option")
corr <- vapply(ans, `[[`, logical(1), "correct")
cor_ans <- anss[corr]
check <- match(value, cor_ans)
right <- cor_ans[stats::na.omit(check)]
wrong <- ans[match(setdiff(value, cor_ans), anss)]
missed <- ans[match(setdiff(cor_ans, value), anss)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cosmetic request: Could you expand on the variable names being created? Thank you

@schloerke
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants