<- list()
answers <- list()
solutions <- list()
types <- list()
explanations <- list() tolerances
Creation of the .Rmd file
This page explains the process of subsetting the lists in the .Rmd-file and what type of content is required.
A template can be downloaded here.
Subsetting
The lists used in the .Rmd to contain the answer options, solutions, etc. can be altered via subsetting.
The lists are initialized as empty lists using list()
Accessing Elements
The different elements of a list can be accessed using two square brackets [[]]
.
There are other ways of accessing elements in a list, however for simplicity reasons, this documentation focuses on [[]]
. The other two have their own applications, which are not necessary for using R/exams
in the way it is described here.
For example, this accesses the first element (of the first element) of the answers
list.
1]] answers[[
Accessing multiple elements, note the use of []
instead of [[]]
, which is necessary to access the elements of list instead of the elements of the elements of the list.
c(1, 3, 5)] #1st, 3rd, 5th element
answers[
1:5] #1st to 5th element answers[
Assigning and Altering Elements
When elements are accessed, they can also be altered, note the use of []
instead of [[]]
when accessing multiple elements, which is necessary to access the elements of list instead of the elements of the elements of the list.
1]] <- 5 #first element of the answer list is 5
solutions[[
c(2, 4)] <- "A" #2nd and 4th answer is "A"
solutions[
1:5] <- 0 #Tolerances for all questions are 0. tolerances[
Please note that the examples in this section should only show the necessary syntax and are not taken from a real example.
Content of the Lists
Using the example of an exercise containing one numeric and one multiple choice question, this section will explain what type of content is put into the lists.
Answers list
This list contains the answer options for single/multiple choice questions.
The exemplary questions are:
What is the correct symbol for gold in the periodic table?
Please calculate the standard deviation \(\sigma\), when the variance is \(\sigma^2 = 2,59\).
These questions will be pasted in the question text section directly in the .Rmd-file.
So the three answer options for the single choice question would be for example: “Ti”, “Au” and “Ag”, which are stored in the answers
list.
For the numeric question, no answer options are needed, therefore an empty string ""
is placed there instead. When creating larger exams with many numeric questions, this can be done automatically for all questions at once, see below:
1]] <- c("Ti", "Au", "Ag")
answers[[2]] <- ""
answers[[
#placeholders for numeric and string questions
for (x in 1:length(types)) {
if (types[x] %in% c("num", "string")) {
<- ""
answers[x]
} }
Solutions list
The solutions
list contains the correct solutions to the questions.
1]] <- "Au"
solutions[[2]] <- sqrt(2.59) soltuions[[
Types
For each question its type needs to be specified, see this section for a description of types. For this example, we have a single choice and a numeric question.
1]] <- "schoice"
types[[2]] <- "num" types[[
Explanations
Explanations are not necessary, however they can be provided to students for putting the answer into context.
1]] <- "The symbol for gold in the periodic table is \"Au\", because it comes from the Latin word \"aurum\"."
explanations[[2]] <- paste("The correct answer is ", sqrt(2.59), ", beacuse the standard deviation is the square root of the variance.") explanations[[
Inside a string “…”, it is necessary to escape certain characters, by placing \
before them, for example quotes.
Tolerances
Tolerances are only needed for numeric questions, they can be 0 or any other value. For all other types, the element in the list is set to 0 by the second part of the code chunk below.
2]] <- 0.001
tolerances[[
for (x in 1:length(solutions)) {
if (tolerances[x] |> unlist() |> is.null()) {
<- 0
tolerances[x]
} }
Tolerances are generally used to account for rounding differences when the resulting number has many decimal places, or the number is very large. However, it is also possible to set the numeric tolerance to 0, for example when asking for the number of continents, which has clearly only one true answer with no sensible tolerance, despite being a numeric question.