FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add new anybox question type to solve #382 by elmstedt · Pull Request #434 · rstudio/learnr · GitHub

/ learnr Public

Add new anybox question type to solve #382 - #434

Open
elmstedt wants to merge 6 commits into
rstudio:mainfrom
elmstedt:master
Open

Add new anybox question type to solve #382#434
elmstedt wants to merge 6 commits into
rstudio:mainfrom
elmstedt:master

Conversation

Copy link
Copy Markdown

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 commented Sep 25, 2020
edited
Loading

Copy link
Copy Markdown


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 thread R/question_anybox.R
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
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Comment thread R/question_anybox.R
min_right = 1,
max_wrong = 0
) {
structure(learnr::question(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Comment thread R/question_anybox.R
Comment on lines +85 to +86
min_right <- max(attr(question, "min_right"), 1)
max_wrong <- max(attr(question, "max_wrong"), 0)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

will then retrieve these from question$options

Comment thread R/question_anybox.R
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
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Copy link
Copy Markdown
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.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

3 participants


Back | FazBrowse Home | New Git URL