Skip to content

Commit

Permalink
Add choices() helper function for matching a set of options with answers
Browse files Browse the repository at this point in the history
Resolves #20
  • Loading branch information
mitchelloharawild committed May 18, 2023
1 parent f21be80 commit 9f5b834
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export(answer_multichoice)
export(answer_numerical)
export(answer_shortanswer)
export(answer_singlechoice)
export(choices)
export(cloze)
export(cloze_type)
export(mchoice)
Expand Down
14 changes: 14 additions & 0 deletions R/answer.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,17 @@ answer_numerical <- function(correct, weight = 1, tolerance = 0, feedback = spri
weight, correct, tolerance, feedback
)
}

#' Create a set of choices for single or multiple choice questions
#'
#' @param A character vector of selectable choices
#' @param A character vector of the correct answers
#'
#' @export
choices <- function(options, answer) {
i <- options %in% answer
if(!any(i)) stop("The correct answer does not exist in the provided options.")
i <- as.integer(i)
names(i) <- options
i
}
14 changes: 14 additions & 0 deletions man/choices.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9f5b834

Please sign in to comment.