Skip to content

Commit

Permalink
Added automatic cloze functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchelloharawild committed Dec 13, 2023
1 parent 3af61e8 commit 94821b8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Generated by roxygen2: do not edit by hand

S3method(cloze,character)
S3method(cloze,numeric)
export(answer_multichoice)
export(answer_numerical)
export(answer_shortanswer)
Expand Down
25 changes: 25 additions & 0 deletions R/answer.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,28 @@ choices <- function(options, answer) {
names(i) <- options
i
}

#' Succinctly create a suitable cloze question
#'
#' @param x The correct answer
#' @param ... Options passed on to other methods
#'
#' @export
cloze <- function(x, ...) {
UseMethod("cloze")
}

#' @export
cloze.numeric <- function(x, ...) {
answer_numerical(x, ...)
}

#' @export
cloze.character <- function(x, choices = NULL, ...) {
if(is.null(choices))
answer_shortanswer(x, ...)
else if(length(x) > 1)
answer_multichoice(choices(choices, x))
else
answer_singlechoice(choices(choices, x))
}

0 comments on commit 94821b8

Please sign in to comment.