read_exercise: Reading LaTeX/Markdown Exercise Files In exams: Automatic Generation of Exams in R

Description

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

Usage

 1 2  read_exercise(file) read_metainfo(file) 

Arguments

 file character. Name of the LaTeX (.tex) or Markdown (.md) file that should be read into R.

Details

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.

Value

read_exercise returns a list with elements

 question a character vector with LaTeX/Markdown code from the question environment (excluding the answerlist environment, if any). questionlist a character vector with LaTeX/Markdown code from the answerlist environment within the question environment (if any). solution a character vector with LaTeX/Markdown code from the solution environment (excluding the answerlist environment, if any). solutionlist a character vector with LaTeX/Markdown code from the answerlist environment within the solution environment (if any). metainfo a list of metainformation options, see below. supplements 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.

 file character with file name (without extension) of the exercise template. markup character indicating whether "latex" or "markdown" markup is used in the exercise. type character indicating exercise type: num, mchoice, schoice, string, or cloze. name character with short name/description (to be used for printing within R). title character with a pretty longer title. section character with sections for groups of exercises (using slashes for subsections like a URL). version character with version of exercise. solution 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). tolerance numeric tolerance limits (of length 1 or 2) for numeric solutions. clozetype character indicating the types of the elements of a cloze exercise. points numeric with (default) points for correct solution. time numeric with (default) time (in seconds) for solution. shuffle logical indicating whether mchoice/schoice answers should be shuffled (in Moodle or other e-learning systems). single logical indicating whether radio buttons should be used in Moodle. length numeric with length of solution. string character with a collapsed string of the solution (and tolerance) for backward compatibility with exams. maxchars character with the maximum number of characters allowed in QTI text answers (exercise type: string). abstention character with the label to be used for an abstention button in schoice/mchoice answers (currently only supported by Moodle).

xexams

Examples

 1 2 3 4 5 6 7 8 9 ## 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]] 

Example output

$question [1] "A machine fills milk into$500$ml packages. It is suspected that the " [2] "machine is not working correctly and that the amount of milk filled differs " [3] "from the setpoint$\\mu_0 = 500$. A sample of$226$packages " [4] "filled by the machine are collected. The sample mean$\\bar{y}$is equal to " [5] "$517.2$and the sample variance$s^2_{n-1}$is equal to " [6] "$262.56$." [7] "" [8] "Test the hypothesis that the amount filled corresponds on average to the " [9] "setpoint. What is the absolute value of the$t$~test statistic?"$questionlist
NULL

$solution [1] "The$t$~test statistic is calculated by:" [2] "\\begin{eqnarray*}" [3] " t & = & \\frac{\\bar y - \\mu_0}{\\sqrt{\\frac{s^2_{n-1}}{n}}}" [4] " = \\frac{517.2 - 500}{\\sqrt{\\frac{262.56}{226}}}" [5] " = 15.958." [6] "\\end{eqnarray*}" [7] "The absolute value of the$t$~test statistic is thus equal to" [8] "$15.958$."$solutionlist
NULL

$metainfo$metainfo$file [1] "tstat"$metainfo$markup [1] "latex"$metainfo$type [1] "num"$metainfo$name [1] "t statistic"$metainfo$title NULL$metainfo$section NULL$metainfo$version NULL$metainfo$solution [1] 15.958$metainfo$tolerance [1] 0.01$metainfo$clozetype NULL$metainfo$points NULL$metainfo$time NULL$metainfo$shuffle [1] FALSE$metainfo$single [1] FALSE$metainfo$length [1] 1$metainfo$string [1] "t statistic: 15.958 (15.948--15.968)"$metainfo$maxchars NULL$metainfo$abstention NULL$supplements
named character(0)
attr(,"dir")
[1] "/work/tmp/tmp/RtmpCjnXkq/file7218706a8b8f/exam1/exercise1"

$question [1] "A machine fills milk into 500ml packages. It is suspected that the " [2] "machine is not working correctly and that the amount of milk filled differs " [3] "from the setpoint$\\mu_0 = 500$. A sample of$226$packages " [4] "filled by the machine are collected. The sample mean$\\bar{y}$is equal to " [5] "517.2 and the sample variance$s^2_{n-1}$is equal to " [6] "262.56." [7] "" [8] "Test the hypothesis that the amount filled corresponds on average to the " [9] "setpoint. What is the absolute value of the t-test statistic?"$questionlist
NULL

solution [1] "The t-test statistic is calculated by:" [2] "" [3] "\\begin{aligned}" [4] " t = \\frac{\\bar y - \\mu_0}{\\sqrt{\\frac{s^2_{n-1}}{n}}}" [5] " = \\frac{517.2 - 500}{\\sqrt{\\frac{262.56}{226}}}" [6] " = 15.958." [7] "\\end{aligned}" [8] "" [9] "The absolute value of the t-test statistic is thus equal to" [10] "15.958."solutionlist
NULL

$metainfo$metainfo$file [1] "tstat"$metainfo$markup [1] "markdown"$metainfo$type [1] "num"$metainfo$name [1] "t statistic"$metainfo$title NULL$metainfo$section NULL$metainfo$version NULL$metainfo$solution [1] 15.958$metainfo$tolerance [1] 0.01$metainfo$clozetype NULL$metainfo$points NULL$metainfo$time NULL$metainfo$shuffle [1] FALSE$metainfo$single [1] FALSE$metainfo$length [1] 1$metainfo$string [1] "t statistic: 15.958 (15.948--15.968)"$metainfo$maxchars NULL$metainfo$abstention NULL$supplements
named character(0)
attr(,"dir")
[1] "/work/tmp/tmp/RtmpCjnXkq/file7218293942d3/exam1/exercise1"


exams documentation built on Sept. 23, 2017, 3 a.m.