This document describes the process for using the exams
(Zeileis et al. 2020) package for creating an exam composed of simple single choice questions, the creation of an export file, and its uploading for import into Canvas. The flow chart below gives a graphical overview of the process.
It is assumed that RStudio is already installed, if not please install it. With RStudio running do the following:
Exam-Creation.Rmd
. This file will be used for installing the library, copying the question template, building the exam, making temporary copies of the exam for proof reading, and finally generating the export file to upload to Canvas.exams
package and load it. Note that once the package has been installed on a computer, this line can be removed or commented out.install.packages("exams", dependencies = TRUE)
library(exams)
It is important to note that pandoc needs to be installed on the system. Unless there is a need to generate pdf output, everything should be ready to start building questions for an exam. See the R/Exams instillation tutorial for additional guidance in instillation issues.
While a single file is used to load the library and generate the exam, each individual exam question is written to its own separate R Markdown .Rmd
file. These files are later combined together to build the exam. It is important that each exam question file is properly written. To facilitate consistency in file structure, and to save time it is recommended to use a template file. The following template is for single choice questions. Other templates are available in the R/Exams First Steps tutorial.
Question
========
Which answer is correct?
Answerlist
----------
* Answer 1
* Answer 2
* Answer 3
* Answer 4
Meta-information
================
exname: question2
extype: schoice
exsolution: 0010
A few pieces of Meta-information
and general issues to consider are worth mentioning when writing and editing questions:
exname
is the question name.extype
is the question type. For simple single choice questions, schoice
is the option to select.exsolution
is the answer key. Each answer must be marked as correct 1
or incorrect 0
. In the sample file above, Answer 3 is the correct answer.Question
, Answerlist
, or Meta-information
.====
or the ---
.====
or the ---
and the text of the question, or answer list.It is possible to have questions with figures. To do this, the questionXXX.Rmd
file must have a code chunk in addition to just the markdown text. The figure graphic can be located anywhere on the system, but the code chunk to include_supplement()
must provide the correct path to the file.
```{r, echo = FALSE, results = "hide"}
include_supplement("map2.jpg", dir = "", recursive = TRUE)
```
Question
========
What is location #3 on the map?
<map2.jpg>
Answerlist
----------
* Answer 1
* Answer 2
* Answer 3
* Answer 4
Meta-information
================
exname: question75
extype: schoice
exsolution: 0010
In the main R Markdown file, the one we’re calling Exam-Creation.Rmd
create a new chunk and add the following code which can be used to copy the template file to create a new file in the same working directory, and open it for editing:
file.copy("question-template.Rmd", "question001.Rmd")
file.edit("question001.Rmd")
I suggest numbering the questions as “question001.Rmd, question002.Rmd, etc.” Doing this makes building an exam easier because the file pattern is simple. Just change the output file and file edit numbers for each new question to be created and run that chunk again.
As described below, it is possible to have Canvas randomize the order of answers when presenting the questions on a quiz. If randomizing the answer is desirable, avoid writing questions that rely on answers such as “all of the above” or “none of the above.” Instead, use wording like “all of the answers” or “none of the answers.”
e
that contains a vector consisting of all the R Markdown files to be included in the exam. Method 1 (commented out) illustrates how to build the vector literally. Method 2 (preferable) shows how to use pattern matching to combine all Rmd files in the directory with the name question
.exams2html()
and exams2pandoc()
to the vector e
to create html and .doc output for review. The onboard help forexams2canvas()
is pretty clear. To call help ?exams2canvas()
.exams_metainfo(exams2pandoc(e))
is used to generate an exam key. This might be useful for proof reading and ensuring the answers are correct. # Method 1: List the files literally
# e <- c("Question01.Rmd", "Question02.Rmd")
# Method 2: List the files based on extension
e <- list.files(pattern = "question.*.Rmd")
# Write file to html for a quick check to see everything is ok
exams2html(e)
# Write file to Word Doc just to have a copy all in one place.
exams2pandoc(e)
# Create an exam key for proofreading purposes.
# Copy the console output to a text file.
exams_metainfo(exams2pandoc(e))
exams2html()
or exams2pandoc()
do not run properly, provided pandoc is installed properly, the issue may be due to unwanted white spaces in the question (see above).Edit
menu >Find in Files
option. Paste in the string or search term to identify which of the question files needs to be edited. RStudio will show which of the questionXXX.Rmd
files needs to be edited.questionXXX.Rmd
files and re-run the code chunk above to generate new output exams. Once the exam is in proper order, it is time to create an export file.To create an export file, apply the function exams2canvas()
. This will generate a zipped QTI file which can be uploaded. At this stage, be sure to properly set how many points each question is worth. However, I think this can be adjusted in a Canvas question bank.
# Export the exam to a zip file for Canvas
exams2canvas(e, name = "tempquiz", points = 3)
When importing into canvas: