Learn R Programming

exams (version 1.9-0)

read_exercise: Reading LaTeX Exercise Files

Description

Reading an exercise in LaTeX format (i.e., after Sweave was run).

Usage

read_exercise(file)
  read_metainfo(file)

Arguments

file
character. Name of the LaTeX file that should be read into R.

Value

  • read_exercise returns a list with elements
  • questiona character vector with LaTeX code from the question environment (excluding the answerlist environment, if any).
  • questionlista character vector with LaTeX code from the answerlist environment within the question environment (if any).
  • solutiona character vector with LaTeX code from the solution environment (excluding the answerlist environment, if any).
  • solutionlista character vector with LaTeX code from the answerlist environment within the solution environment (if any).
  • metainfoa list of metainformation options, see below.
  • supplementsa 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.
  • filecharacter with file name (without extension) of the Sweave exercise template.
  • typecharacter indicating exercise type: num, mchoice, schoice, string, or cloze.
  • namecharacter with short name/description (to be used for printing within R).
  • titlecharacter with a pretty longer title.
  • sectioncharacter with sections for groups of exercises (using slashes for subsections like a URL).
  • versioncharacter with version of exercise.
  • solutioncorrect 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).
  • tolerancenumeric tolerance limits (of length 1 or 2) for numeric solutions.
  • clozetypecharacter indicating the types of the elements of a cloze exercise.
  • pointsnumeric with (default) points for correct solution.
  • timenumeric with (default) time (in seconds) for solution.
  • shufflelogical indicating whether mchoice/schoice answers should be shuffled (in Moodle or other e-learning systems).
  • singlelogical indicating whether radio buttons should be used in Moodle.
  • lengthnumeric with length of solution.
  • stringcharacter with a collapsed string of the solution (and tolerance) for backward compatibility with exams.

Details

read_exercise extracts the LaTeX code from the question and solution environments of the exercise LaTeX file, extracting the answerlist environments 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).

See Also

xexams

Examples

Run this code
## 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")[[1]][[1]]

Run the code above in your browser using DataLab