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.
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 going through this tutorial you should have: - R installed - spreadsheet application, like MS Excel, Google Sheets, Libre Calc …etc.
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 |
---|---|---|---|---|---|---|---|---|
:———- | :—– | :——– | :– | :– | :– | :– | :– | :————- |
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
This is where you specify the question text. This can’t be empty at any question row.
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>
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
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.
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 |
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 | ∫{1}{2}{2xdx} | 3 | num_q |
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 |
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 |
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 |
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.
mcq
tf_q
short_ans
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 | ∫{1}{2}{2xdx} | 3 | num_q |
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.
## categories names question A
## 1 Ques/hist Q1 Who's buried in **Grant's tomb**? *Grant
## 2 Ques/hist Q2 What two people are entombed in **Grant's tomb?** No one
## 3 Ques/hist Q3 Grant was buried in a tomb in New York City T
## 4 Ques/science Q4 The sun rises in the West. F
## 5 Ques/hist Q5 Who's buried in Grant's tomb? Grant
## 6 Ques/math Q6 Two plus two equals 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
## '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 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.