R markdown for generating a formatted exam from a csv of questions
This repository shows an example of an R markdown script (exam.Rmd) that reads in a csv file of exam questions and turns it into a formatted exam. By using the knitr
functions implemented in RStudio, you can easily knit the Rmd file into html, markdown, or Word documents.
- Download exam.Rmd.
- Generate a csv file with your exam questions. The repository includes an example: examquestions.csv
- You can include as many columns as you want for various types of meta-data, but the fields that you absolutely need to run the script are:
Question
,Type
,Points
,CorrectAnswer
.
- There are formats defined for the following question types:
multiple-choice
,T/F
,short-answer
,long-answer
, andimage-labels
.
- For the
multiple-choice
type, you will additionally need to defineLure1
,Lure2
, andLure3
. These will be presented along with the correct answer in a random order. - For the
image-labels
type, you will additionally need to defineImage
, which will be the filename of the image you want to present. - Need another format? Add a function to the
defineFormats
chunk, and include it as an option in the if-statement inpresentQuestions
chunk.
- Edit the exam information in the YAML header.
- Edit the instructions after the
loadQuestions
chunk. - Seed your
seedNum
- an arbitrary number that will be used to reset the randomization. This will let you reproducibly generate different versions of the exam. - You can additionally edit the
dplyr
code in theloadQuestions
chunk to sort your questions by whatever variable you want (in the example,Week
), or to filter them according to other variables that you've included in your csv file. - Knit the exam.Rmd file to whatever format you wish.
- Important note: R markdown does not like to preserve large patches of white-space. So I would recommend knitting to Word doc format, then going through the file to add the appropriate amount of space after each short- or long-answer question. If anyone comes up with a better fix, let me know (inserting multiple
\n
calls doesn't work).
After knitting, you will have an exam.doc or exam.html file. See exam_output.md for an example of the formatted output.
The script also generates a csv file that contains your exam key. See examquestions_withkey_v123.csv for an example key. The key will be labeled with your seed version number.
Happy teaching!
Author: Maureen Ritchey, February 2017