forms_schoice: Create Interaction Forms for Different Exercise Types

View source: R/forms.R

forms_schoiceR Documentation

Create Interaction Forms for Different Exercise Types

Description

Helper functions for exams2forms to create the interaction forms for different R/exams exercise types: single-choice (schoice), multiple-choice (mchoice), text (string), or numeric (num).

Usage

forms_schoice(answerlist, solution,
  display = c("buttons", "dropdown"), obfuscate = TRUE)

forms_mchoice(answerlist, solution,
  display = c("buttons", "dropdown"), obfuscate = TRUE)

forms_string(answer, width = NULL,
  usecase = TRUE, usespace = FALSE, regex = FALSE, obfuscate = TRUE)

forms_num(answer, tol = 0, width = NULL,
  usespace = FALSE, regex = FALSE, obfuscate = TRUE)

Arguments

answerlist

character vector of answer alternatives for a single-choice or multiple-choice answer.

solution

logical vector indicating which alternatives in answerlist are correct. Must have the same length as answerlist. For forms_schoice exactly one element of solution must be TRUE.

display

character. Should the interaction for single-choice or multiple-choice forms be displayed with buttons (radio buttons or checkboxes, respectively) or with drop-down menus?

answer

character (for forms_string) or numeric (for forms_num). Correct answer(s).

width

numeric. Width of the input box in characters. Defaults to the length of answer.

usecase

logical. Should the evaluation of the input be case-sensitive?

usespace

logical. Should the evaluation of the input assess white spaces?

regex

logical. Should the evaluation of the input employ regular expressions?

tol

numeric. Tolerance for the evaluation of numeric input.

obfuscate

logical. Should the correct answer be obfuscated when embedded in the HTML source code? If FALSE, it is included as plain text.

Value

A character string with the HTML or Markdown code for the interaction forms to be embedded in R/Markdown or Quarto documents. For a short introduction see https://www.R-exams.org/tutorials/exams2forms/.

Examples

## single-choice: What is the third letter of the latin alphabet?
forms_schoice(c("A", "B", "C", "D"), c(FALSE, FALSE, TRUE, FALSE),
  obfuscate = FALSE)

## multiple-choice: Which of these numbers are prime?
forms_mchoice(c("1", "2", "3", "4"), c(FALSE, TRUE, TRUE, FALSE),
  obfuscate = FALSE)

## string: Which base R function estimates linear regression models?
forms_string("lm", width = 10, obfuscate = FALSE)

## numeric: A population of 1000 grows with a nominal rate of 10% per period.
## How big is the population after three periods?
forms_num(1000 * exp(0.1 * 3), tol = 0.1, width = 10, obfuscate = FALSE)

exams2forms documentation built on May 9, 2025, 3 a.m.