Overview

The package exams2forms provides several building blocks for embedding exercises written with the R package exams (also known as R/exams) in interactive documents or quizzes written with rmarkdown or quarto.

The idea is that the dynamic exercises in R/exams' Rmd (R/Markdown) or Rnw (R/LaTeX) format can also be reused in HTML documents, web pages, or online books. This facilitates their use for self-paced learning and self-assessment without the need for a learning management system etc. And for (summative) assessments the same dynamic exercises could then be exported to different learning management systems or employed in written exams.

All R/exams exercise types are supported:

  • Single-choice (schoice).
  • Multiple-choice (mchoice).
  • Numeric (num).
  • Text (string).
  • Cloze combining all of the previous elements (cloze).

Many of the ideas as well as the code in the package have been adapted from the webexercises package, authored by Dale Barr and Lisa DeBruine.

First examples

As quick demonstration for R/exams exercises embedded into an HTML document, the two examples from the First Steps tutorial are included below: The single-choice exercise swisscapital and the numeric exercise deriv, both in three random variations.

What is the seat of the federal authorities in Switzerland (i.e., the de facto capital)?

There is no de jure capital but the de facto capital and seat of the federal authorities is Bern.

  • False
  • False
  • False
  • True
  • False

What is the seat of the federal authorities in Switzerland (i.e., the de facto capital)?

There is no de jure capital but the de facto capital and seat of the federal authorities is Bern.

  • False
  • False
  • True
  • False
  • False

What is the seat of the federal authorities in Switzerland (i.e., the de facto capital)?

There is no de jure capital but the de facto capital and seat of the federal authorities is Bern.

  • False
  • True
  • False
  • False
  • False

What is the derivative of \(f(x) = x^{7} e^{3.9 x}\), evaluated at \(x = 0.67\)?

Using the product rule for \(f(x) = g(x) \cdot h(x)\), where \(g(x) := x^{7}\) and \(h(x) := e^{3.9 x}\), we obtain \[ \begin{aligned} f'(x) &= [g(x) \cdot h(x)]' = g'(x) \cdot h(x) + g(x) \cdot h'(x) \\ &= 7 x^{7 - 1} \cdot e^{3.9 x} + x^{7} \cdot e^{3.9 x} \cdot 3.9 \\ &= e^{3.9 x} \cdot(7 x^6 + 3.9 x^{7}) \\ &= e^{3.9 x} \cdot x^6 \cdot (7 + 3.9 x). \end{aligned} \] Evaluated at \(x = 0.67\), the answer is \[ e^{3.9 \cdot 0.67} \cdot 0.67^6 \cdot (7 + 3.9 \cdot 0.67) = 11.860944. \] Thus, rounded to two digits we have \(f'(0.67) = 11.86\).

What is the derivative of \(f(x) = x^{4} e^{3.1 x}\), evaluated at \(x = 0.53\)?

Using the product rule for \(f(x) = g(x) \cdot h(x)\), where \(g(x) := x^{4}\) and \(h(x) := e^{3.1 x}\), we obtain \[ \begin{aligned} f'(x) &= [g(x) \cdot h(x)]' = g'(x) \cdot h(x) + g(x) \cdot h'(x) \\ &= 4 x^{4 - 1} \cdot e^{3.1 x} + x^{4} \cdot e^{3.1 x} \cdot 3.1 \\ &= e^{3.1 x} \cdot(4 x^3 + 3.1 x^{4}) \\ &= e^{3.1 x} \cdot x^3 \cdot (4 + 3.1 x). \end{aligned} \] Evaluated at \(x = 0.53\), the answer is \[ e^{3.1 \cdot 0.53} \cdot 0.53^3 \cdot (4 + 3.1 \cdot 0.53) = 4.343937. \] Thus, rounded to two digits we have \(f'(0.53) = 4.34\).

What is the derivative of \(f(x) = x^{5} e^{3.6 x}\), evaluated at \(x = 0.7\)?

Using the product rule for \(f(x) = g(x) \cdot h(x)\), where \(g(x) := x^{5}\) and \(h(x) := e^{3.6 x}\), we obtain \[ \begin{aligned} f'(x) &= [g(x) \cdot h(x)]' = g'(x) \cdot h(x) + g(x) \cdot h'(x) \\ &= 5 x^{5 - 1} \cdot e^{3.6 x} + x^{5} \cdot e^{3.6 x} \cdot 3.6 \\ &= e^{3.6 x} \cdot(5 x^4 + 3.6 x^{5}) \\ &= e^{3.6 x} \cdot x^4 \cdot (5 + 3.6 x). \end{aligned} \] Evaluated at \(x = 0.7\), the answer is \[ e^{3.6 \cdot 0.7} \cdot 0.7^4 \cdot (5 + 3.6 \cdot 0.7) = 22.440478. \] Thus, rounded to two digits we have \(f'(0.7) = 22.44\).

In addition to the question and the interaction element, there are three buttons providing the following functionality.

Button Function
✓ Check the answer and display whether it is correct or not. When clicked, the symbol is toggled and ↰ is displayed, which can be clicked to hide the solution again.
? Display the full correct solution explanation.
↺ Switch to the next question.

Inclusion of the solution explanation is optional and the next question button is only displayed if there is more than one random variation of a question. The icons and mouseover text can also be adapted (see below).

To set up a similar standalone file with these two exercises, the exams2qebquiz() interface from the exams2forms package can be used:

library("exams2forms")
exams2webquiz(c("swisscapital.Rmd", "deriv.Rmd"), n = 3)

More elaborate examples

To showcase some more exercise types, the following examples from the R/exams package are used: capitals (multiple-choice), function (string/text), fruit (numeric with table and images), lm2 (cloze containing string, multiple-choice, numeric, and single-choice elements as well as an embedded data file).

Which of the following cities are the capital of the corresponding country?

  • True. New Delhi is the capital of India.
  • True. Warsaw is the capital of Poland.
  • False. The capital of New Zealand is Wellington.
  • True. Tokyo is the capital of Japan.
  • True. Riyadh is the capital of Saudi Arabia.

What is the name of the R function for logistic regression?

glm is the R function for logistic regression. See ?glm for the corresponding manual page.

Given the following information:

orange \(+\) orange \(+\) pineapple = \(508\)
pineapple \(+\) banana \(+\) pineapple = \(735\)
banana \(+\) banana \(+\) orange = \(203\)

Compute:

banana \(+\) orange \(+\) pineapple = \(\text{?}\)

The information provided can be interpreted as the price for three fruit baskets with different combinations of the three fruits. This corresponds to a system of linear equations where the price of the three fruits is the vector of unknowns \(x\):

\(x_1 =\) banana \(x_2 =\) orange \(x_3 =\)