| add_cloze | R Documentation |
Functions for adding elements to the meta-information of an exercise and for formatting the collected meta-information, respectively.
add_cloze(solution, choices = NULL, type = NULL, tolerance = NULL,
answertag = TRUE, ...)
format_metainfo(field)
initialize_exercise()
solution |
solution for an answer field in an exercise. See also the details below. |
choices |
vector of answer alternatives in a single-choice or multiple-choice exercise. See also the details below. |
type |
character. Optional specification of the type for an
answer field, by default inferred from |
tolerance |
numeric. Tolerance to be used in case of a numeric
|
answertag |
logical. Should an ANSWERi tag be returned for inclusion in the text? |
... |
optional arguments for formatting a numeric |
field |
character indicating whether the |
The function add_cloze(solution) adds meta-information to an
internal list in order to facilitate tracking of the elements in an
exercise, especially in cloze exercises.
If solution is numeric, a num element is added along with
the corresponding tolerance, by default selected via
num_to_tol(solution). Optionally, the solution can be formatted
via fmt, e.g., to obtain a rounding to a given number
of digits etc.
If solution is a character, a string element is added.
Additionally, solution can be a numeric or character vector or
matrix in which case all elements are added (row-wise) to the meta-information
and suitably-formatted answer tags are included as well
(if answertag = TRUE, default).
Finally, if solution is a named logical vector, an mchoice or
schoice element is added. The type can either be specified
explicitly and otherwise schoice is used if solution has exactly
one TRUE element. Alternatively, add_cloze(solution, choices) can be used
to define single-choice or multiple-choice exercises where choices
contains a vector of answer alternatives and solution a subset of
choices with the correct solution(s). See also the examples below.
Using format_metainfo(type) the collected meta-information can be extracted,
suitably formatted for inclusion in an exercise. The format_metainfo("answerlist")
is intended to be included at the end of the question section while the other
types ("type", "solution", and "tolerance") are intended
to be included in the meta-information tags.
The function initialize_exercise() resets and initializes the exercise
meta-information in the package's internal environment. Usually, this does
not have be called by the user because it is called automatically prior to
processing an exercise file. However, it is still provided for testing
and illustration purposes as in the examples below.
answerlist
## initialize meta-information (done automatically within xweave())
initialize_exercise()
## add num, string, schoice, and mchoice elements
add_cloze(123.456789)
add_cloze("ABC")
add_cloze("high", c("low", "neutral", "high"))
add_cloze(c(
"Zurich is the capital of Switzerland." = FALSE,
"Italian is an official language in Switzerland." = TRUE,
"Switzerland is part of the European Union." = FALSE
), type = "mchoice")
## add a numeric matrix
tab <- matrix(10^(1:4), ncol = 2, byrow = TRUE,
dimnames = list(c("Top", "Bottom"), c("Left", "Right")))
add_cloze(tab)
## format collected meta-information
format_metainfo("type")
format_metainfo("solution")
format_metainfo("tolerance")
writeLines(format_metainfo("answerlist"))
## re-initialize cloze meta-information for cleanup
initialize_exercise()
## equivalent specifications of single/multiple-choice elements
add_cloze("high", c("low", "neutral", "high"), type = "schoice")
add_cloze(c("low" = FALSE, "neutral" = FALSE, "high" = TRUE), type = "schoice")
## format collected meta-information
format_metainfo("type")
format_metainfo("solution")
writeLines(format_metainfo("answerlist"))
## re-initialize cloze meta-information for cleanup
initialize_exercise()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.