Reading an exercise in either LaTeX format (i.e.,
after Sweave
was run) or
Markdown format (i.e., after knit
was run).
read_exercise(file, markup = NULL, exshuffle = NULL)
read_metainfo(file, markup = NULL, exshuffle = NULL)
read_exercise
returns a list with elements
a character vector with LaTeX/Markdown code from the question environment (excluding the answerlist environment, if any).
a character vector with LaTeX/Markdown code from the answerlist environment within the question environment (if any).
a character vector with LaTeX/Markdown code from the solution environment (excluding the answerlist environment, if any).
a character vector with LaTeX/Markdown code from the answerlist environment within the solution environment (if any).
a list of metainformation options, see below.
a character vector with paths to supplementary files such as graphics or data files (if any).
read_metainfo
returns a list with the following elements.
Most elements may also be NULL
(or empty) if the underlying
information is not specified in the file
. If file
specifies
extra information, there may also be additional list elements.
character with file name (without extension) of the exercise template.
character indicating whether "latex"
or "markdown"
markup is used in the exercise.
character indicating exercise type: num
, mchoice
,
schoice
, string
, or cloze
.
character with short name/description (to be used for printing within R).
character with a pretty longer title.
character with sections for groups of exercises (using slashes for subsections like a URL).
character with version of exercise.
correct solution. The type/value depends on the
type
of the exercise: num
leads to a numeric vector (of length 1
or 2), mchoice
/schoice
lead to logical vector, string
to
a character vector (of length 1), and cloze
leads to a list of
solutions (depending on clozetype
).
numeric tolerance limits (of length 1 or 2) for numeric solutions.
character indicating the types of the elements of a
cloze
exercise.
numeric with (default) points for correct solution.
numeric with (default) time (in seconds) for solution.
logical indicating whether mchoice
/schoice
answers should be shuffled (in Moodle or other e-learning systems).
logical indicating whether radio buttons should be used in Moodle.
numeric with length of solution
.
character with a collapsed string of the solution (and tolerance)
for backward compatibility with exams
.
character with the maximum number of characters allowed in QTI text answers (exercise type: string).
character with the label to be used for an abstention button in schoice/mchoice answers (currently only supported by Moodle).
character. Name of the LaTeX (.tex
) or
Markdown (.md
) file that should be read into R.
character specifying whether file
is a "latex"
or "markdown"
exercise. By default (NULL
) it is
inferred from the file
extension.
logical or integer. If the exshuffle
argument is non-NULL
it is used to overrule the exshuffle
tag from the file
(e.g., exshuffle = FALSE
can be used
to keep all available answers without permutation).
read_exercise
extracts the LaTeX/Markdown code from the question
and solution environments/sections of the exercise file, extracting
the corresponding answerlists separately (if any). Paths to supplementary
files (such as graphics or data files) are stored and the
metainformation is extracted (by calling read_metainfo
which
also includes sanity checks).
The supported metainformation commands are described in detail in
vignette("exams2", package = "exams")
, see Table 2. Essentially
the extype
command in is mapped to the type
element of the returned list etc. (see the Value section below), using
the right storage mode for each command (numeric, character, logical).
Additionally, there is an exextra
command which allows to set
up arbitrary additional metainformation elements.
xexams
## xexams() uses read_exercise() by default to read in
## each individual exercise, e.g., here for only a single
## exam with only a single exercise the result is:
set.seed(1090)
xexams("tstat.Rnw")[[1]][[1]]
## the corresponding Markdown version has:
set.seed(1090)
xexams("tstat.Rmd")[[1]][[1]]
Run the code above in your browser using DataLab