Generation of Exams in IMS QTI 1.2 and 2.1 Format

Automatic generation of exams in IMS QTI 1.2 and 2.1 format.

exams2qti12(file, n = 1L, nsamp = NULL, dir = ".",
    name = NULL, quiet = TRUE, edir = NULL,
    tdir = NULL, sdir = NULL, verbose = FALSE,
    resolution = 100, width = 4, height = 4, svg = FALSE, encoding = "",
    num = NULL, mchoice = NULL,
    schoice = mchoice, string = NULL, cloze = NULL,
    template = "qti12", duration = NULL,
    stitle = "Exercise", ititle = "Question",
    adescription = "Please solve the following exercises.",
    sdescription = "Please answer the following question.",
    maxattempts = 1, cutvalue = 0, solutionswitch = TRUE,
    zip = TRUE, points = NULL,
    eval = list(partial = TRUE, negative = FALSE),
    converter = NULL, xmlcollapse = FALSE,
    flavor = c("plain", "openolat", "canvas"), …)

exams2qti21(file, n = 1L, nsamp = NULL, dir = ".", name = NULL, quiet = TRUE, edir = NULL, tdir = NULL, sdir = NULL, verbose = FALSE, resolution = 100, width = 4, height = 4, svg = FALSE, encoding = "", num = NULL, mchoice = NULL, schoice = mchoice, string = NULL, cloze = NULL, template = "qti21", duration = NULL, stitle = "Exercise", ititle = "Question", adescription = "Please solve the following exercises.", sdescription = "Please answer the following question.", maxattempts = 1, cutvalue = 0, solutionswitch = TRUE, zip = TRUE, points = NULL, eval = list(partial = TRUE, negative = FALSE), converter = NULL, base64 = TRUE, mode = "hex", …)

make_itembody_qti12(rtiming = FALSE, shuffle = FALSE, rshuffle = shuffle, minnumber = NULL, maxnumber = NULL, defaultval = NULL, minvalue = NULL, maxvalue = NULL, cutvalue = NULL, enumerate = TRUE, digits = NULL, tolerance = is.null(digits), maxchars = 12, eval = list(partial = TRUE, negative = FALSE), fix_num = TRUE, flavor = "plain")

make_itembody_qti21(shuffle = FALSE, defaultval = NULL, minvalue = NULL, maxvalue = NULL, enumerate = TRUE, digits = NULL, tolerance = is.null(digits), maxchars = 12, eval = list(partial = TRUE, negative = FALSE), solutionswitch = TRUE)


character. A specification of a (list of) exercise files.


integer. The number of copies to be compiled from file.


integer. The number(s) of exercise files sampled from each list element of file. Sampling without replacement is used if possible. (Only if some element of nsamp is larger than the length of the corresponding element in file, sampling with replacement is used.)


character. The default is the current working directory.


character. A name prefix for resulting exercises and ZIP file.


logical. Should output be suppressed when calling xweave?


character specifying the path of the directory (along with its sub-directories) in which the files in file are stored (see also xexams).


character specifying a temporary directory, by default this is chosen via tempfile. Note that this is cleaned up and potentially temporary files are deleted.


character specifying a directory for storing supplements, by default this is chosen via tempfile.


logical. Should information on progress of exam generation be reported?

resolution, width, height

numeric. Options for rendering PNG (or SVG) graphics passed to xweave.


logical. Should graphics be rendered in SVG or PNG (default)?


character, passed to xweave.


function or named list applied to numerical (i.e., type num) questions. If num is a function, num will be used for generating the item body of the question, see function make_itembody_qti12() (or make_itembody_qti21()). If num is a named list, these arguments will be passed to function make_itembody_qti12() (or make_itembody_qti21() using exams2qti21()).

mchoice, schoice, string, cloze

function or named list applied to multiple choice, single choice, string, and cloze questions (i.e., type mchoice, schoice, string, and cloze), respectively. See argument num for more details.


character. The IMS QTI 1.2 or 2.1 template that should be used. Currently, the package provides "qti12.xml" and "qti21.xml".


integer. Set the duration of the exam in minutes.


character. A title that should be used for the sections. May be a vector of length 1 to use the same title for each section, or a vector containing different section titles.


character. A title that should be used for the assessment items. May be a vector of length 1 to use the same title for each item, or a vector containing different item titles. Note that the maximum of different item titles is the number of sections/questions that are used for the exam.


character. Description (of length 1) for the overall assessment (i.e., exam).


character. Vector of descriptions for each section.


integer. The maximum attempts for one question, may also be set to Inf.


numeric. The cutvalue at which the exam is passed.


logical. Should the question/item solutionswitch be enabled? In OLAT this means that the correct solution is shown after an incorrect solution was entered by an examinee (i.e., this is typically only useful if maxattempts = 1).


logical. Should the resulting XML file (plus supplements) be zipped?


integer. How many points should be assigned to each exercise? Note that this argument overules any exercise points that are provided within an "\expoints{}" tag in the .Rnw file. The vector of points supplied is expanded to the number of exercises in the exam.


named list, specifies the settings for the evaluation policy, see function exams_eval.


logical. Should supplementary files be embedded using Base 64 coding? Argument base64 may also be a character vector of file suffixes that should be encoded, e.g. base64 = c("png", "rda") will only encode PNG images and binary .rda files. If set to NULL only image files will be encoded.


character. See function tth.

rtiming, shuffle, rshuffle, minnumber, maxnumber, defaultval, minvalue, maxvalue

arguments used for IMS QTI 1.2 item construction, for details see the XML specification (see IMS Global Learning Consortium, Inc. 2012), especially Section 4. Genereting IMS QTI 2.1 items using exams2qti21() the arguments have similar meaning.


logical. Insert potential solutions in enumerated list?


integer. How many digits should be used for num exercises?


logical. Should tolerance intervals be used for checking if the supplied num answer/number is correct? The default is to use tolerance intervals if digits = NULL.


numeric. Lower bound for the number of characters in fill-in-blank fields. The actual number of characters is selected as the maximum number of characters of this value and the actual solution.


logical. This is a special flag to enable/force the display of the correct solutions for numeric exercises/answers as well as to obtain results when archiving tests. Note that this is a workaround, which works e.g. within OLAT.


character. Argument passed on to make_exercise_transform_html. The default for converter is set to "ttm" unless there are Rmd exercises in file where "pandoc" is used.


logical or character. Should line breaks be collapsed in the XML code. If TRUE everything is collapsed with spaces (" ") but other collapse characters could be supplied.


character. Which QTI 1.2 “flavor” should be used? Some learning management systems require that the QTI XML tags are used in a rather specific and idiosyncratic way. Typically, users should not set this argument directly but use the convenience interfaces exams2canvas or exams2openolat instead (which use the flavor argument internally along with further customizations).

further arguments passed on to make_exercise_transform_html.


The Question & Test Interoperability (QTI) is an international XML standard for specifying e-learning tests (IMS Global Learning Consortium, Inc. 2012ab). The standard evolved over various versions with the first release culminating in the QTI 1.2 standard and the stable version of the second release currently at QTI 2.1. While both versions share many similarities, they differ in many details. Hence, separate functions exams2qti12 and exams2qti21 are provided. The former has already been thoroughly tested and the latter is still in beta testing stage and might change in future releases.

exams2qti12 produces a .zip file that may be uploaded (e.g. in OLAT). This includes the final XML file of the exam/assessment as well as possible supplement folders that include images, data sets etc. used for the exam. It proceeds by (1) calling xweave on each exercise, (2) reading the resulting LaTeX code, (3) transforming the LaTeX code to HTML, and (4) embedding the HTML code in a XML file using the IMS QTI 1.2 standards for assessments and question items.

For steps (1) and (2) the standard drivers in xexams are used. In step (3), a suitable transformation function is set up on the fly using make_exercise_transform_html, see also the details section in exams2html.

For step (4), the function will cycle through all questions and exams to generate the final XML file in IMS QTI 1.2 standard. Therefore, each question will be included in the XML as one section. The replicates of each question will be written as question items of the section.

The function uses the XML template for IMS QTI 1.2 assessments and items to generate the exam (per default, this is the XML file qti12.xml provided in the xml folder of this package). The assessment template must provide one section including one item. exams2qti12 will then use the single item template to generate all items, as well as the assessment and section specifications set within the template.

The default template will generate exams/assessments that sample one replicate of a question/item for each section. The usual procedure in exam/assessment generation would be to simply copy \& paste the XML template of the package and adapt it to the needs of the user. Note that all specifiers that have a leading ## in the XML template will be replaced by suitable code in exams2qti12 and should always be provided in the template. I.e., the user may add additional tags to the XML template or modify certain specifications, like the number of replicates/items that should be sampled for each section etc.

Per default, the individual question/item bodies are generated by function make_itembody_qti12, i.e. make_itembody_qti12 checks the type of the question and will produce suitable XML code. Note that for each question type, either the arguments of make_itembody_qti12 may be set within num, mchoice, schoice, string and cloze in exams2qti12, by providing a named list of specifications that should be used, or for each questiontype, a function that produces the item body XML code may be provided to num, mchoice, schoice, string and cloze. E.g., mchoice = list(shuffle = TRUE) will force only multiple choice questions to have a shuffled answerlist.

Note that in OLAT/OpenOLAT num exercises are not officially supported but in fact work correctly. The only drawback is that in certain settings the correct solution is not shown at the end of the assessment (although it is used for all internal computations). Therefore, two workarounds are implemented. Either fix_num can be set to TRUE (default), then a fix is added by double-checking the result, or digits can be set to a fixed value (e.g., digits = 2). In the latter case, the num exercise is represented by a string. Then the answer must be provided exactly to the decimal places specified (e.g., if the exact solution is 16.4562, then the correct answer in the test will be "16.46", i.e., a character string of 5 characters).

Generating exams/assessment in IMS QTI 2.1 format using exams2qti21() and make_itembody_qti21() is performed in a similar way as described above. Note that the IMS QTI 2.1 generators are still work in progress. The generated XML files have been validated using the IMS validator provided at http://membervalidator.imsglobal.org/qti/ (when it was still freely available). Furthermore, a selection of generated exams/assessments has been tested using the ONYX Editor and Player, see https://www.onyx-editor.de/.


exams2qti12 and exams2qti21 return a list of exams as generated by xexams.

make_itembody_qti12 and make_itembody_qti21 return a function that generates the XML code for the itembody tag in IMS QTI 1.2 and IMS QTI 2.1 format.


IMS Global Learning Consortium, Inc. (2012a). IMS Question & Test Interoperability: ASI XML Binding Specification Final Specification Version 1.2. http://www.imsglobal.org/question/qtiv1p2/imsqti_asi_bindv1p2.html

IMS Global Learning Consortium, Inc. (2012b). IMS Question & Test Interoperability (QTI) XSD Binding Version 2.1 Final. http://www.imsglobal.org/question/qtiv2p1/imsqti_bindv2p1.html

BPS Bildungsportal Sachsen GmbH (2014). ONYX Testsuite. http://www.bps-system.de/cms/en/products/onyx-testsuite/

Zeileis A, Umlauf N, Leisch F (2014). Flexible Generation of E-Learning Exams in R: Moodle Quizzes, OLAT Assessments, and Beyond. Journal of Statistical Software, 58(1), 1--36. http://www.jstatsoft.org/v58/i01/.

See Also

xexams, ttm, tth, tex2image, make_exercise_transform_html,

  • exams2qti12
  • make_itembody_qti12
  • exams2qti21
  • make_itembody_qti21
  • exams2qti
  • make_itembody_qti
## load package and enforce par(ask = FALSE)
options(device.ask.default = FALSE)

## define an exams (= list of exercises)
myexam <- list(
  c("tstat", "ttest", "confint"),
  c("regression", "anova"),
  c("scatterplot", "boxhist"),

## output directory
dir.create(mydir <- tempfile())

## generate .zip with QTI 1.2 exam in temporary directory
## using a few customization options
exams2qti12(myexam, n = 3, dir = mydir,
  maxattempts = 3,
  num = list(digits = 1),
  mchoice = list(shuffle = TRUE, enumerate = FALSE)
# }
Documentation reproduced from package exams, version 2.3-6, License: GPL-2 | GPL-3

Community examples

Looks like there are no examples yet.