Package 'moodlequiz'

Title: R Markdown format for 'Moodle' XML cloze quizzes
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.
Authors: Mitchell O'Hara-Wild [aut, cre] (ORCID: <https://orcid.org/0000-0002-3813-7155>), Emi Tanaka [aut] (ORCID: <https://orcid.org/0000-0002-1455-259X>)
Maintainer: Mitchell O'Hara-Wild <[email protected]>
License: MIT + file LICENSE
Version: 0.2.1.9000
Built: 2026-05-10 09:05:33 UTC
Source: https://github.com/numbats/moodlequiz

Help Index


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

  • cloze_shortanswer(): Creates a short-answer question where the student provides a text response.

  • cloze_singlechoice(): Generates a single-choice question where students select one correct answer from a list.

  • cloze_multichoice(): Creates a multiple-choice question where students can select one or more correct answers.

  • cloze_numerical(): Generates a numerical question where students input a numeric response with optional tolerance.

  • cloze(): Automatic question types based on the class of the answers.

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