Skip to contents

Convenience function for creating a basic quiz in HTML format from the arguments captured by ..., where the type of each question is determined automatically from the class of the arguments.

Usage

quizz(
  ...,
  render_if = knitr::is_html_output(),
  title = "Quiz",
  show_box = TRUE,
  show_check = TRUE
)

Arguments

...

Each argument should be a named vector, see Details.

render_if

Logical, whether or not to render the output. By default, this argument uses knitr::is_html_output().

title

Atomic character, default: 'Quiz'

show_box

Logical, whether or not to draw a box around the quiz. Default: TRUE

show_check

Logical, whether or not to show a button to check answers. Default: TRUE

Value

NULL, this function is called for its side effect of printing HTML code using cat().

Details

The function renders questions captured by the arguments in .... The name of each argument is the text of the question. The value of each argument determined the question type and its correct answer. The following types of questions are supported:

"torf()"

The argument should be a single value of type logical, e.g.: "The answer to this question is true." = TRUE

"mcq()"

The argument should be a vector of type character. The first element is taken as the correct answer; the order of answers is randomized. E.g.: "This multiple choice question has three answers." = c("Correct", "Incorrect", "Not sure")

"fitb()"

The argument should be of type numeric. If the vector is atomic, the first element is taken as the correct answer, e.g.: "Provide an exact floating point answer of 0.81" = 0.81. If the vector has two elements, the second element is taken as the tolerance tol, e.g.: "Here, 0.8 will be correct." = c(0.81, 0.01). If the vector is of type integer, the tolerance is set to zero, e.g.: "The answer is 4." = 4L

Alternatively, ... may contain a single atomic character referring to a text file that contains the questions, see examples.

Examples

# Quiz from arguments:
invisible(capture.output(theorytools:::quizz(
"The answer to this question is true." = TRUE,
"This multiple choice question has three answers." =
 c(answer = "Correct", "Incorrect", "Not sure"),
"Provide an exact floating point answer of 0.81" = 0.81,
render_if = TRUE
)))
# From a file:
quizz_file <- tempfile()
writeLines(
c("The answer is true. = TRUE",
"The answer is correct = c(answer = \"Correct\", \"Incorrect\", \"Not sure\")",
"The answer is exactly .81 = 0.81",
"But here, .8 is also fine = c(0.81, .01)",
"Write the word 'true' = c('true', 'TRUE')",
"Here, answer exactly 4. = 4L")
, quizz_file)
invisible(capture.output(theorytools:::quizz(quizz_file, render_if = TRUE)))