From 083212f27be1a97d5dd6ba962ce68bfaddc442bb Mon Sep 17 00:00:00 2001 From: mitchelloharawild Date: Thu, 14 Dec 2023 00:06:13 +1100 Subject: [PATCH] Remove legacy moodlequiz_cloze exams package format --- DESCRIPTION | 1 - NAMESPACE | 4 - R/quiz.R | 221 ---------------------------------------- man/cloze.Rd | 13 +-- man/mchoice.Rd | 23 ----- man/moodlequiz.Rd | 2 +- man/moodlequiz_cloze.Rd | 62 ----------- man/schoice.Rd | 18 ---- 8 files changed, 8 insertions(+), 336 deletions(-) delete mode 100644 R/quiz.R delete mode 100644 man/mchoice.Rd delete mode 100644 man/moodlequiz_cloze.Rd delete mode 100644 man/schoice.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 5b74c34..2d28dd4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -20,7 +20,6 @@ Language: es Roxygen: list(markdown = TRUE) RoxygenNote: 7.2.3 Imports: - exams, knitr, rlang, rmarkdown, diff --git a/NAMESPACE b/NAMESPACE index 265d92e..e4c5c4d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -8,9 +8,5 @@ export(answer_shortanswer) export(answer_singlechoice) export(choices) export(cloze) -export(cloze_type) -export(mchoice) export(moodlequiz) -export(moodlequiz_cloze) -export(schoice) import(rmarkdown) diff --git a/R/quiz.R b/R/quiz.R deleted file mode 100644 index 5dc252c..0000000 --- a/R/quiz.R +++ /dev/null @@ -1,221 +0,0 @@ - -#' R Markdown format for Moodle XML cloze quizzes -#' -#' Provides an alternative interface to working with the exams package for -#' producing Moodle questions of the cloze type. -#' -#' @inheritParams rmarkdown::html_document -#' -#' @import rmarkdown -#' -#' @export -moodlequiz_cloze <- function(self_contained = TRUE, - extra_dependencies = NULL, - theme = NULL, - includes = NULL, - lib_dir = NULL, - md_extensions = NULL, - pandoc_args = NULL, - ...) { - pre_knit <- function(input, ...) { - # Parse yaml - front_matter <- rmarkdown::yaml_front_matter(input) - keep_rmd <- front_matter$keep_rmd %||% FALSE - - # Get cloze types - ## Replace cloze inline chunks with `r cloze()` functions - cloze_pattern <- "(?\n
  • \n {"), - "{" - ), - out_file - ) - - exams::exams2html(input_fn, name = file_nm) - stop("Done! This error is a quick hack to stop render() proceeding pointlessly.") - } - - # return format - output_format( - knitr = knitr_options(), - pandoc = pandoc_options(to = "markdown+raw_tex", ext = ".md"), - pre_knit = pre_knit, - base_format = rmarkdown::md_document( - ... - ) - ) -} - -cloze_table <- function() { - table <- list() - list( - add = function(result) { - table[[length(table) + 1]] <<- result - }, - list = function() { - table - }, - length = function() { - length(table) - }, - reset = function() { - table <<- list() - } - ) -} - -cloze_table <- cloze_table() - -#' Cloze question -#' -#' Use this function to declare a cloze question in an R Markdown document -#' with the `moodlequiz::moodlequiz_cloze` output format. -#' -#' @param x The question's solution. -#' -#' @export -cloze <- function(x) { - cloze_table$add(x) - paste0("##ANSWER", cloze_table$length(), "##") -} - -#' @export -cloze_type <- function(x, ...) { - UseMethod("cloze_type") -} -cloze_type.numeric <- function(x, ...) "num" -cloze_type.character <- function(x, ...) "string" -cloze_type.moodle_schoice <- function(x, ...) "schoice" -cloze_type.moodle_mchoice <- function(x, ...) "mchoice" -cloze_type.default <- function(x, ...) stop("Unsupported cloze question type.") - -cloze_questionlist <- function() { - paste0( - # needed the base:: since `c` seems to be overwritten somewhere - do.call(base::c, lapply(cloze_table$list(), function(x) paste("*", cloze_question(x)))), - collapse = "\n" - ) -} -cloze_question <- function(x, ...) { - UseMethod("cloze_question") -} -cloze_question.numeric <- function(x, ...) "" -cloze_question.character <- function(x, ...) "" -cloze_question.moodle_schoice <- function(x, ...) { - attr(x, "opts") -} - -cloze_answerlist <- function() { - paste0( - do.call(base::c, lapply(cloze_table$list(), function(x) paste("*", cloze_answer(x)))), - collapse = "\n" - ) -} -cloze_answer <- function(x, ...) { - UseMethod("cloze_answer") -} -cloze_answer.numeric <- function(x, ...) x -cloze_answer.character <- function(x, ...) x -cloze_answer.moodle_schoice <- function(x, ...) { - pos <- stringr::str_locate_all(x, stringr::fixed("1"))[[1]][,1] - qs <- attr(x, "opts") - qs[pos] <- paste0("**", attr(x, "opts")[pos], "**") - qs -} - -#' Single choice question -#' -#' Use this function in a cloze inline chunk to describe a single choice -#' question. -#' -#' @param opts The options to choose from (character vector) -#' @param sol The correct solution (the correct value from `opts`, or the -#' position of the correct value) -#' -#' @export -schoice <- function(opts, sol) { - if(is.character(sol)) sol <- match(sol, opts) - sol_code <- rlang::rep_along(opts, "0") - sol_code[sol] <- "1" - sol_code <- paste0(sol_code, collapse = "") - return(structure(sol_code, opts = opts, class = "moodle_schoice")) -} - -#' Multiple choice question -#' -#' Use this function in a cloze inline chunk to describe a single choice -#' question. -#' -#' Note: this is only supported for exams 2.4. CRAN version is at 2.3-6. -#' Install the latest from R-Forge. -#' `install.packages("exams", repos = "http://R-Forge.R-project.org")` -#' -#' @param opts The options to choose from (character vector) -#' @param sol The correct solution (the correct value from `opts`, or the -#' position of the correct value) -#' @export -mchoice <- function(opts, sol) { - if(is.character(sol)) sol <- match(sol, opts) - sol_code <- rlang::rep_along(opts, "0") - sol_code[sol] <- "1" - sol_code <- paste0(sol_code, collapse = "") - return(structure(sol_code, opts = opts, class = c("moodle_mchoice", "moodle_schoice"))) -} diff --git a/man/cloze.Rd b/man/cloze.Rd index 4493ec7..b3432d8 100644 --- a/man/cloze.Rd +++ b/man/cloze.Rd @@ -1,15 +1,16 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/quiz.R +% Please edit documentation in R/answer.R \name{cloze} \alias{cloze} -\title{Cloze question} +\title{Succinctly create a suitable cloze question} \usage{ -cloze(x) +cloze(x, ...) } \arguments{ -\item{x}{The question's solution.} +\item{x}{The correct answer} + +\item{...}{Options passed on to other methods} } \description{ -Use this function to declare a cloze question in an R Markdown document -with the \code{moodlequiz::moodlequiz_cloze} output format. +Succinctly create a suitable cloze question } diff --git a/man/mchoice.Rd b/man/mchoice.Rd deleted file mode 100644 index 35b93d9..0000000 --- a/man/mchoice.Rd +++ /dev/null @@ -1,23 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/quiz.R -\name{mchoice} -\alias{mchoice} -\title{Multiple choice question} -\usage{ -mchoice(opts, sol) -} -\arguments{ -\item{opts}{The options to choose from (character vector)} - -\item{sol}{The correct solution (the correct value from \code{opts}, or the -position of the correct value)} -} -\description{ -Use this function in a cloze inline chunk to describe a single choice -question. -} -\details{ -Note: this is only supported for exams 2.4. CRAN version is at 2.3-6. -Install the latest from R-Forge. -\code{install.packages("exams", repos = "http://R-Forge.R-project.org")} -} diff --git a/man/moodlequiz.Rd b/man/moodlequiz.Rd index 6c61918..880e600 100644 --- a/man/moodlequiz.Rd +++ b/man/moodlequiz.Rd @@ -24,7 +24,7 @@ its size).} \item{extra_dependencies}{Extra dependencies as a list of the \code{html_dependency} class objects typically generated by -\code{htmltools::\link{htmlDependency}()}.} +\code{\link[htmltools:htmlDependency]{htmltools:htmlDependency()}}.} \item{theme}{One of the following: \itemize{ diff --git a/man/moodlequiz_cloze.Rd b/man/moodlequiz_cloze.Rd deleted file mode 100644 index 023cdb4..0000000 --- a/man/moodlequiz_cloze.Rd +++ /dev/null @@ -1,62 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/quiz.R -\name{moodlequiz_cloze} -\alias{moodlequiz_cloze} -\title{R Markdown format for Moodle XML cloze quizzes} -\usage{ -moodlequiz_cloze( - self_contained = TRUE, - extra_dependencies = NULL, - theme = NULL, - includes = NULL, - lib_dir = NULL, - md_extensions = NULL, - pandoc_args = NULL, - ... -) -} -\arguments{ -\item{self_contained}{Produce a standalone HTML file with no external -dependencies, using data: URIs to incorporate the contents of linked -scripts, stylesheets, images, and videos. Note that even for self contained -documents MathJax is still loaded externally (this is necessary because of -its size).} - -\item{extra_dependencies}{Extra dependencies as a list of the -\code{html_dependency} class objects typically generated by -\code{htmltools::\link{htmlDependency}()}.} - -\item{theme}{One of the following: -\itemize{ -\item A \code{\link[bslib:bs_theme]{bslib::bs_theme()}} object (or a list of \code{\link[bslib:bs_theme]{bslib::bs_theme()}} argument values) -\itemize{ -\item Use this option for custom themes using Bootstrap 4 or 3. -\item In this case, any \code{.scss}/\code{.sass} files provided to the \code{css} -parameter may utilize the \code{theme}'s underlying Sass utilities -(e.g., variables, mixins, etc). -} -\item \code{NULL} for no theme (i.e., no \code{\link[rmarkdown:html_dependency_bootstrap]{html_dependency_bootstrap()}}). -\item A character string specifying a \href{https://bootswatch.com/3/}{Bootswatch 3} -theme name (for backwards-compatibility). -}} - -\item{includes}{Named list of additional content to include within the -document (typically created using the \code{\link[rmarkdown]{includes}} function).} - -\item{lib_dir}{Directory to copy dependent HTML libraries (e.g. jquery, -bootstrap, etc.) into. By default this will be the name of the document with -\code{_files} appended to it.} - -\item{md_extensions}{Markdown extensions to be added or removed from the -default definition of R Markdown. See the \code{\link[rmarkdown]{rmarkdown_format}} for -additional details.} - -\item{pandoc_args}{Additional command line options to pass to pandoc} - -\item{...}{Additional function arguments to pass to the base R Markdown HTML -output formatter \code{\link[rmarkdown]{html_document_base}}} -} -\description{ -Provides an alternative interface to working with the exams package for -producing Moodle questions of the cloze type. -} diff --git a/man/schoice.Rd b/man/schoice.Rd deleted file mode 100644 index 83b9ad8..0000000 --- a/man/schoice.Rd +++ /dev/null @@ -1,18 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/quiz.R -\name{schoice} -\alias{schoice} -\title{Single choice question} -\usage{ -schoice(opts, sol) -} -\arguments{ -\item{opts}{The options to choose from (character vector)} - -\item{sol}{The correct solution (the correct value from \code{opts}, or the -position of the correct value)} -} -\description{ -Use this function in a cloze inline chunk to describe a single choice -question. -}