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.
How to use
- 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:
- There are formats defined for the following question types:
- For the
multiple-choicetype, you will additionally need to define
Lure3. These will be presented along with the correct answer in a random order.
- For the
image-labelstype, you will additionally need to define
Image, which will be the filename of the image you want to present.
- Need another format? Add a function to the
defineFormatschunk, and include it as an option in the if-statement in
- Edit the exam information in the YAML header.
- Edit the instructions after the
- 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
dplyrcode in the
loadQuestionschunk 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
\ncalls 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.
Author: Maureen Ritchey, February 2017