Title: R Markdown format for 'Moodle' XML cloze quizzes
Version: 0.2.0
Description: Enables the creation of 'Moodle' quiz questions using literate programming with R Markdown. This makes it easy to quickly create a quiz that can be randomly replicated with new datasets, questions, and options for answers.
License: MIT + file LICENSE
Encoding: UTF-8
Language: es
RoxygenNote: 7.3.3
Imports: rlang, rmarkdown, bookdown, xfun, yaml
URL: https://github.com/numbats/moodlequiz, https://numbats.github.io/moodlequiz/
BugReports: https://github.com/numbats/moodlequiz/issues
Suggests: knitr, testthat (≥ 3.0.0)
Config/testthat/edition: 3
NeedsCompilation: no
Packaged: 2025-12-01 13:58:59 UTC; mitchell
Author: Mitchell O'Hara-Wild ORCID iD [aut, cre], Emi Tanaka ORCID iD [aut]
Maintainer: Mitchell O'Hara-Wild <mail@mitchelloharawild.com>
Repository: CRAN
Date/Publication: 2025-12-06 12:10:07 UTC

Create a set of choices for single or multiple choice questions

Description

Create a set of choices for single or multiple choice questions

Usage

choices(options, answer)

Arguments

options

A character vector of selectable choices

answer

A character vector of the correct answers

Value

A named vector of choices suitable for use with cloze_singlechoice() and cloze_multichoice()

See Also

cloze_singlechoice(), cloze_multichoice()


Generate Cloze-Type Questions for Moodle

Description

These functions create cloze-type questions for Moodle quizzes, designed for use with inline R code chunks in an R Markdown document formatted with the moodlequiz::moodlequiz output format.

Usage

cloze_shortanswer(
  options,
  weight = max(options),
  feedback = "",
  case_sensitive = FALSE
)

cloze_multichoice(
  options,
  weight = max(options),
  feedback = "",
  type = c("vertical", "horizontal"),
  shuffle = FALSE
)

cloze_singlechoice(
  options,
  weight = max(options),
  feedback = "",
  type = c("dropdown", "vertical", "horizontal"),
  shuffle = FALSE
)

cloze_numerical(answer, weight = 1, tolerance = 0, feedback = "")

cloze(x, ...)

Arguments

options

A named vector of answer options. For single/multiple choice questions the choices() helper function can help create this vector. Names correspond to answers, and values specify their weights (e.g., 100 for a correct answer or partial weights for partially correct answers). For multiple-choice and single-choice questions, this includes both correct and distractor options.

weight

A numeric value specifying the weight for the question. Defaults to the highest weight in options.

feedback

A character vector providing feedback for answers.

case_sensitive

Logical. For cloze_shortanswer, whether the answer should be case-sensitive. Defaults to FALSE.

type

A character string specifying the presentation style of the options. For cloze_multichoice, valid values are "vertical" or "horizontal". For cloze_singlechoice, valid values are "dropdown", "vertical", or "horizontal".

shuffle

Logical. For cloze_multichoice and cloze_singlechoice, whether the answer options should be shuffled. Defaults to FALSE.

answer

A numeric value specifying the correct numerical answer(s).

tolerance

A numeric value specifying the acceptable range of deviation for cloze_numerical answers. Defaults to 0.

x

For cloze(), the correct answer which also determines the question type (e.g. numeric will use cloze_numerical() and character will use cloze_shortanswer() or cloze_singlechoice()/cloze_multichoice() if selectable options are given as the second argument).

...

Additional arguments passed to other cloze() methods (such as the available options and other ⁠cloze_*()⁠ arguments).

Value

A character string containing the Moodle-compatible XML or inline text for the specified cloze question(s).

Functions

Examples

# Short-answer question: Where is the best coffee?
cloze_shortanswer(
  options = c("Melbourne" = 1),
  case_sensitive = FALSE
)

# Multiple-choice question: Select all lower-case answers
cloze_multichoice(
  options = c("a" = 1, "F" = 0, "g" = 1, "V" = 0, "K" = 0),
  type = "vertical"
)

# Where is Melbourne?
cloze_singlechoice(
  choices(
    c("New South Wales", "Victoria", "Queensland", "Western Australia",
      "South Australia", "Tasmania", "Australian Capital Territory",
      "Northern Territory"),
    "Victoria"
  ),
  type = "dropdown"
)

# Numerical question: Pick a number between 1 and 10
cloze_numerical(
  answer = 5.5,
  tolerance = 4.5
)

# Automatic cloze questions
cloze(42) # Numerical
cloze("Australia") # Short answer
cloze("rep_len", c("rep", "rep.int", "rep_len", "replicate")) # Single choice
cloze(c("A", "B", "C"), LETTERS) # Multiple choice


R Markdown format for Moodle XML quizzes

Description

Provides an alternative interface to working with the exams package for producing Moodle questions any type.

Usage

moodlequiz(
  replicates = 1L,
  self_contained = TRUE,
  extra_dependencies = NULL,
  theme = NULL,
  includes = NULL,
  lib_dir = NULL,
  md_extensions = NULL,
  pandoc_args = NULL,
  ...
)

Arguments

replicates

The number of times the questions are rendered, useful for producing multiple versions of the same quiz with different random samples. To keep identify replicates of questions for random importation into Moodle we recommend organising the materials into categories using top level headers.

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).

extra_dependencies

Extra dependencies as a list of the html_dependency class objects typically generated by htmltools::htmlDependency().

theme

One of the following:

  • A bslib::bs_theme() object (or a list of bslib::bs_theme() argument values)

    • Use this option for custom themes using Bootstrap 4 or 3.

    • In this case, any .scss/.sass files provided to the css parameter may utilize the theme's underlying Sass utilities (e.g., variables, mixins, etc).

  • NULL for no theme (i.e., no html_dependency_bootstrap()).

  • A character string specifying a Bootswatch 3 theme name (for backwards-compatibility).

includes

Named list of additional content to include within the document (typically created using the includes function).

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 ⁠_files⁠ appended to it.

md_extensions

Markdown extensions to be added or removed from the default definition of R Markdown. See the rmarkdown_format for additional details.

pandoc_args

Additional command line options to pass to pandoc

...

Additional function arguments to pass to the base R Markdown HTML output formatter html_document_base

Value

R Markdown output format to pass to rmarkdown::render()


Generate Moodle Quiz XML Output for R Markdown

Description

This function is intended for internal generation of the XML output. It is strongly recommended that you use the ⁠[moodlequiz::moodlequiz()]⁠ output format, which provides a higher-level interface for creating Moodle-compatible quizzes.

Usage

moodlequiz_xml(
  replicate = "",
  self_contained = TRUE,
  extra_dependencies = NULL,
  theme = NULL,
  includes = NULL,
  lib_dir = NULL,
  md_extensions = NULL,
  pandoc_args = NULL,
  ...
)

Arguments

replicate

A character string specifying the how many replications of the quiz should be produced.

self_contained

Logical. If TRUE, the output document will be self-contained, embedding resources directly into the file. Defaults to TRUE.

extra_dependencies

Additional dependencies to include in the output. These can be specified as an html_dependency object or a list of such objects.

theme

A character string specifying the theme for the output. This can be a standard theme name or a custom CSS file.

includes

Additional content to include in the output. This should be a list of named elements, such as in_header, before_body, and after_body.

lib_dir

Directory to copy library files for the output. If NULL, no library files are copied.

md_extensions

A character string specifying Markdown extensions to be passed to Pandoc.

pandoc_args

Additional arguments to pass to Pandoc.

...

Additional arguments passed to bookdown::html_document2()

Value

An R Markdown output format object.

See Also

moodlequiz()