Using ‘GIFTr’ Package To Prepare ‘MOODLE’ Quiz from Spreadsheet

Omar I. Elashkar

What is GIFTr?

GIFTr package in intended to help course creators to upload questions to MOODLE and other LMS for quizzes. GIFTr takes dataframe or tibble of questions of four types: mcq, numerical questions, true or false and short answer,and export it a text file formatted in MOODLE GIFT format. You can prepare a spreadsheet in any software and import it in R and generate any number of questions with HTML, markdown and LATEX support.

Aim of this document

The aim of vignette is to highlight the most useful features of GIFTr in preparing a flexible MOODLE quiz as quick as possible with the lowest possibility of errors.

Before you start.

Before going through this tutorial you should have: - R installed - spreadsheet application, like MS Excel, Google Sheets, Libre Calc …etc.

How to start your quiz spreadsheet?

The data passed would differ slightly according to question type, however generally you need to have:-


Here is what your spreadsheet heading should look like.

categories names question A B C D E question_type

categories column

If you want to add high control for your quiz, you can specify categories in hierarchical order. For example if you want to create this quiz under category Questions and subcategory to be history and under that chapter2 , you can write it as Ques/hist/chap2

Questions column

This is where you specify the question text. This can’t be empty at any question row.

Markdown and HTML Support

You can use markdown formatting like **bold** and italic and the more advance formatting like tables. You also can use HTML tags in this question like <sub> and <sup>

LATEX Support

You can use latex as inline or block code, between single $ or double $$ dollar sign. However you have to be careful if you have equal sign or curly brackets to use  to escape it. For more about escaping characters in GIFT check MOODLE docs

Answers column

You can have one or more answer columns. The formatting can differ slightly from question to another. Below I will highlight the most important tips. #### HTML, markdown and LATEX Like question text, answers can be formatted with HTML, markdown or LATEX.

MCQ

When you write MCQs answers you have the flexibility of marking more than one correct answer to be preceded by asterisk *. If you mark only one answer by asterisk, you will get an MCQ question of single answer type and this answer will hold 100% of credit. If you mark many answers, answer will take partial equally divided positive credit and the wrong answers will take equally divided negative credit. This is to prevent selecting all the answers to get 100% credit as MOODLE don’t allow it automatically.
Below is a whole example of a single and a multiple answer MCQ respectively.
categories names question A B C D E question_type
Ques/hist Q1 Who’s buried in Grant’s tomb? *Grant no one#Was true for 12 years, but Grant’s remains were buried in the tomb in 1897 Napoleon#He was buried in France Churchill#He was buried in England Mother Teresa#She was buried in India mcq
Ques/hist Q2 What two people are entombed in Grant’s tomb? No one *Grant *Grant’s wife Grant’s father mcq


If you don’t want to have a multiple answers MCQ and want to write ONLY single answer MCQ and want a quicker approach than asterisk, you can neglect asterisk and position the all right answers to be in the first column answer. Below is an example of single answer MCQ with the correct answer in column A

categories names question A B C D E question_type
Ques/hist Q1 Who’s buried in Grant’s tomb? Grant no one#Was true for 12 years, but Grant’s remains were buried in the tomb in 1897 Napoleon#He was buried in France Churchill#He was buried in England Mother Teresa#She was buried in India mcq

Numeric Entry

You can right single or multiple answers of numeric entry questions with ranges and limits. - Answer with no preceding credit will take 100% credit. - If you precede an answer with partial credit, for example, ’‘%80%2’, typing 2 will give 80% of the credit for this question. - You can use ranges and limits like. - ‘4..6’ is any answer minimum 4 and maximum 6 - ‘5:1’ the answer is 5 plus or minus 1 Below are examples of numeric questions
categories names question A B C D E question_type
7 Ques/math Q7 What is the value of pi (to 3 decimal places)? 3.14159:0.0005 num_q
8 Ques/math Q8 What is the value of pi (to 3 decimal places)? 3.141..3.142 num_q
9 Ques/hist Q9 When was Ulysses S. Grant born? 1822:0 %50%1822:2#Not very percise num_q
10 Ques/math Q10 2<sup>2</sup> 4 num_q
11 Ques/hist Q11 \[\int_\{1\}^\{2\}\{2xdx\}\] 3 num_q

Short Answer Question

You can use a single or multiple answers to be the answer with the same concept of partial credits of numeric questions, where no preceding credit is 100% and %90% is 90% …etc.
categories names question A B C D E question_type
5 Ques/hist Q5 Who’s buried in Grant’s tomb? Grant Ulysses S. Grant Ulysses Grant short_ans
6 Ques/math Q6 Two plus two equals four 4 short_ans

True or False

For true or false questions, you just right ‘T’ or ‘F’ in the first answer column.
categories names question A B C D E question_type
3 Ques/hist Q3 Grant was buried in a tomb in New York City T tf_q
4 Ques/science Q4 The sun rises in the West. F tf_q

Answer Feedback

You can always add a feedback for any answer selected by adding # sign after the answer.

A B C D E
1 *Grant no one#Was true for 12 years, but Grant’s remains were buried in the tomb in 1897 Napoleon#He was buried in France Churchill#He was buried in England Mother Teresa#She was buried in India
9 1822:0 %50%1822:2#Not very percise

Question type column

The question types supported are mcq, numeric entry, true or false and short answer. You don’t have to specify those if you have only one type of them as you can use a single function specific to create those types of questions, however if you want to use GIFTr() function, you can’t leave this column empty.

Question names column

If you want to specify a specific keyword or ID for a question, you can specify it here. However you don’t have to worry about that this as question name is automatically generated to be the first 40 words of the questions column.

Here is how a full data may like.

categories names question A B C D E question_type
Ques/hist Q1 Who’s buried in Grant’s tomb? *Grant no one#Was true for 12 years, but Grant’s remains were buried in the tomb in 1897 Napoleon#He was buried in France Churchill#He was buried in England Mother Teresa#She was buried in India mcq
Ques/hist Q2 What two people are entombed in Grant’s tomb? No one *Grant *Grant’s wife Grant’s father mcq
Ques/hist Q3 Grant was buried in a tomb in New York City T tf_q
Ques/science Q4 The sun rises in the West. F tf_q
Ques/hist Q5 Who’s buried in Grant’s tomb? Grant Ulysses S. Grant Ulysses Grant short_ans
Ques/math Q6 Two plus two equals four 4 short_ans
Ques/math Q7 What is the value of pi (to 3 decimal places)? 3.14159:0.0005 num_q
Ques/math Q8 What is the value of pi (to 3 decimal places)? 3.141..3.142 num_q
Ques/hist Q9 When was Ulysses S. Grant born? 1822:0 %50%1822:2#Not very percise num_q
Ques/math Q10 2<sup>2</sup> 4 num_q
Ques/hist Q11 \[\int_\{1\}^\{2\}\{2xdx\}\] 3 num_q

Import to R

It doesn’t matter how you import to R, you can use readxl package or read.csv() or what ever you like to import your spreadsheet as dataframe or tibble. A build-in data called GIFTrData is implemented here as example of spreadsheet after importing.

library(GIFTr)
head(GIFTrData)
##     categories names                                          question
## 1    Ques/hist    Q1                 Who's buried in **Grant's tomb**?
## 2    Ques/hist    Q2 What two people are entombed in **Grant's tomb?**
## 3    Ques/hist    Q3       Grant was buried in a tomb in New York City
## 4 Ques/science    Q4                        The sun rises in the West.
## 5    Ques/hist    Q5                     Who's buried in Grant's tomb?
## 6    Ques/math    Q6                               Two plus two equals
##        A
## 1 *Grant
## 2 No one
## 3      T
## 4      F
## 5  Grant
## 6   four
##                                                                                   B
## 1 no one#Was true for 12 years, but Grant's remains were buried in the tomb in 1897
## 2                                                                            *Grant
## 3                                                                              <NA>
## 4                                                                              <NA>
## 5                                                                  Ulysses S. Grant
## 6                                                                                 4
##                                  C                                  D
## 1 Napoleon#He was buried in France Churchill#He was buried in England
## 2                    *Grant's wife                     Grant's father
## 3                             <NA>                               <NA>
## 4                             <NA>                               <NA>
## 5                             <NA>                      Ulysses Grant
## 6                             <NA>                               <NA>
##                                       E question_type
## 1 Mother Teresa#She was buried in India           mcq
## 2                                  <NA>           mcq
## 3                                  <NA>          tf_q
## 4                                  <NA>          tf_q
## 5                                  <NA>     short_ans
## 6                                  <NA>     short_ans
str(GIFTrData)
## 'data.frame':    11 obs. of  9 variables:
##  $ categories   : chr  "Ques/hist" "Ques/hist" "Ques/hist" "Ques/science" ...
##  $ names        : chr  "Q1" "Q2" "Q3" "Q4" ...
##  $ question     : chr  "Who's buried in **Grant's tomb**?" "What two people are entombed in **Grant's tomb?**" "Grant was buried in a tomb in New York City" "The sun rises in the West." ...
##  $ A            : chr  "*Grant" "No one" "T" "F" ...
##  $ B            : chr  "no one#Was true for 12 years, but Grant's remains were buried in the tomb in 1897" "*Grant" NA NA ...
##  $ C            : chr  "Napoleon#He was buried in France" "*Grant's wife" NA NA ...
##  $ D            : chr  "Churchill#He was buried in England" "Grant's father" NA NA ...
##  $ E            : chr  "Mother Teresa#She was buried in India" NA NA NA ...
##  $ question_type: chr  "mcq" "mcq" "tf_q" "tf_q" ...

GIFTr Function

GIFTr() function is the main function of GIFTr Package. It arguments are:- - data: dataframe or tibble of the questions data - questions: name or index of the questions column - answers: a vector of names or indices of answers column(s) - categories: name or index of categories column if available, Default: NULL - question_name: Default is NULL and you don’t have to pass it. If you want them, it will be name or index of the questions names column. If NULL, it will be the first 40 letters of the question title. - question_type name or index of the questions type column. - mcq_answer_column: This parameter you can use on GIFTrData_2 as the answers of MCQs are in the first column and you have not multiple answer mcq. Default: FALSE - output: directory of .txt file name the questions will be exported to. The generated text will be appended to this file if it is already there, if not a new file will be created.

GIFTr::GIFTr(data = GIFTrData, question_names = 2, 
             questions = 3, answers = c(4:8), 
             categories = 1, question_type = 9,
            output = file.path(tempdir(), "quiz.txt"))  
## Total Number of Questions passed: 11
## 
## ====
## ====
## ====
## ====
## MCQ questions input count: 2 
## MCQ questions with single answer passed: 1 
## MCQ questions with multiple answers passed: 1 
## Error found: 0 
## No valid question found : 0 
## No valid answer found: 0
## 
## ====
## ====
## ====
## Done MCQ!
## ===
## Numerical questions input count: 5 
## Numerical questions with single answer passed: 4 
## Numerical questions questions with multiple answers passed: 1 
## Error found: 0 
## No valid question found : 0 
## No valid answer found: 0
## 
## ====
## ====
## ====
## Done Numerical questions!
## ====
## total short answer questions passed is 2. 
## Valid answer: 2 
## error in 0 
## 0 no question has been found 
## 0 no valid answer has been found
## 
## ====
## ====
## ====
## Done Short Answer questions!
## ====
## T/F questions passed input: 2 
## T/F questions Passed: 2 
## Error found: 0 
## No question found : 0 
## No valid answer found: 0
## 
## ====
## ====
## ====
## Done T/F questions!
## ====

Now you have a file called quiz.txt in temporary directory that has the questions ready to be imported by MOODLE. You can simply use only “quiz.txt” to make the file permanent in the home directory.


You can also use specific functions if your dataframe holds only one type of questions. Check the documentation mcq(), num_q, tf_q() and short_ans() functions.