1 Introduction

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.

Figure 1.1: Flow chart illustrating the process of using the exams package to create and exam and then to upload it to Canvas.

1.1 Install Library and Dependencies

It is assumed that RStudio is already installed, if not please install it. With RStudio running do the following:

  1. In the library where the exam or exams are to be built for a given class, create a new RStudio project.
  2. Create a new R Markdown file. It might be called something like 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.
  3. In the newly created R Markdown file, add the following chunk to install the 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.

1.2 Basic Question Format

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.
  • Do not remove the lines Question, Answerlist, or Meta-information.
  • Do not remove the the ==== or the ---.
  • Make sure that there is no blank line between the ==== or the --- and the text of the question, or answer list.
  • There should be only a single blank line after the question stem and after the answer list.
  • Spaces at the end of an answer can cause problems when building a test. If there are trailing white spaces, the questions will not compile properly into an exam. Going back and finding these issues can be time consuming and frustrating. Preventing them in the first place helps tremendously. Probably the best way to prevent and find unwanted white spaces or carriage returns is by enabling white space display in RStudio. Enable white space display by going to: Tools > Global Options > Code > Display > tick the selection box to enable “Show white space characters” > and click “OK.”

1.3 Questions with Figures

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

2 Writing and Creating Questions

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.”

3 Build an Exam and Check It

  1. Create a new code chunk using the example below.
  2. The code creates a variable 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.
  3. The code applies the function 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().
  4. The function exams_metainfo(exams2pandoc(e)) is used to generate an exam key. This might be useful for proof reading and ensuring the answers are correct.
  5. Ctrl+Shift+Enter to run the script, or run it line by line to test it.
    # 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))

4 Editing questions

5 Create an Export File to Send to Canvas

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:

References

Zeileis, Achim, Bettina Gruen, Friedrich Leisch, and Nikolaus Umlauf. 2020. Exams: Automatic Generation of Exams in r. http://www.R-exams.org/.