Learn R Programming

moodlequiz (version 0.2.0)

cloze_questions: 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, ...)

Value

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

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

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

Run this code
# 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

Run the code above in your browser using DataLab