### Solution Field by Type Examples Source: https://github.com/cran/exams.git/blob/master/_autodocs/types.md Illustrates the expected format of the `solution` field within `metainfo` for different exercise types. ```r ## Solution Field by Type | Type | Solution Format | |------|-----------------| | schoice | logical vector | c(FALSE, TRUE, FALSE, FALSE) | | mchoice | logical vector | c(TRUE, FALSE, TRUE, FALSE) | | num | numeric vector | c(3.14, 2.71) | | string | character | "correct answer" | | cloze | list of solutions | list(c(F,T,F), 2.5, "text") | ``` -------------------------------- ### Enabling TinyTeX Installation Source: https://github.com/cran/exams.git/blob/master/NEWS.md Install the TinyTeX LaTeX distribution if no other LaTeX system is currently installed. This provides a lightweight, up-to-date LaTeX environment for R package users. ```R tinytex::install_tinytex() ``` -------------------------------- ### Minimal Markdown Exercise Example Source: https://github.com/cran/exams.git/blob/master/_autodocs/README.md A basic Markdown file structure for an exercise, including question, options, solution, and meta-information. ```markdown # Question What is 2 + 2? # Question List * 3 * 4 * 5 * 6 # Solution The answer is 4. # Solution List * FALSE * TRUE * FALSE * FALSE # Meta information extype: schoice exsolution: 0100 exname: Addition ``` -------------------------------- ### Minimal LaTeX Example Source: https://github.com/cran/exams.git/blob/master/_autodocs/README.md A basic LaTeX file structure for an exercise, using R code chunks and Sexpr for dynamic content, along with meta-information. ```latex <>= a <- 2 b <- 2 @ \begin{question} What is \Sexpr{a} + \Sexpr{b}? \end{question} \begin{solution} The answer is \Sexpr{a + b}. \end{solution} \begin{answerlist} \item 3 \item 4 \item 5 \item 6 \end{answerlist} %% Meta information %% extype: schoice %% exsolution: 0100 %% exname: Addition ``` -------------------------------- ### Grade Thresholds and Labels Example Source: https://github.com/cran/exams.git/blob/master/_autodocs/types.md Provides an example of defining grade thresholds (as fractions of max points) and corresponding labels for mapping scores to grades. ```r mark <- c(0.5, 0.60, 0.75, 0.85) # Fraction of max points labels <- c("F", "D", "C", "B", "A") # Corresponding grades # Mapping: # score < 0.50 → "F" (fail) # 0.50 ≤ score < 0.60 → "D" (poor) # 0.60 ≤ score < 0.75 → "C" (satisfactory) # 0.75 ≤ score < 0.85 → "B" (good) # 0.85 ≤ score → "A" (excellent) ``` -------------------------------- ### Example Usage of exams2moodle() Source: https://github.com/cran/exams.git/blob/master/_autodocs/core-functions.md This example demonstrates how to use the exams2moodle() function to generate two replications of an exam from an R Markdown file, saving the output to a specified directory with a given name. ```r exams2moodle("exercise.Rmd", n = 2, dir = "moodle_export", name = "quiz") ``` -------------------------------- ### Exercise Metadata Structure Example Source: https://github.com/cran/exams.git/blob/master/_autodocs/metadata.md This R code snippet shows the structure of the 'metainfo' list, which contains metadata for exercises. It includes fields for exercise type, name, length, solution, and other configuration options. ```r metainfo <- list( type = "schoice", # Exercise type: schoice, mchoice, num, string, cloze name = "exercise_id", # Exercise name/identifier length = 4, # Number of answer options or cloze items solution = c(F,T,F,F), # Correct answer(s): logical, numeric, or character tolerance = c(0, 0), # Tolerance for numeric answers shuffle = FALSE, # Whether answer options were shuffled clozetype = NULL, # For cloze: vector of type per item string = "Q: 2nd option",# Human-readable solution string file = "ex.tex", # Source file name markup = "latex", # Markup language used points = 1, # Points value (if assigned) seed = NULL, # Random seed (if used) tags = NULL # Custom metadata tags ) ``` -------------------------------- ### Generate multiple PDF exams with custom naming Source: https://github.com/cran/exams.git/blob/master/_autodocs/core-functions.md Example demonstrating how to generate multiple PDF exams using `exams2pdf()`. It specifies the exercise files, the number of replications, the output directory, and a base name for the output files. ```r # Generate 3 PDF exams with plain template exams2pdf(c("ex1.Rnw", "ex2.Rnw", "ex3.Rnw"), n = 3, dir = "exams", name = "myexam") ``` -------------------------------- ### match_exams_device() Source: https://github.com/cran/exams.git/blob/master/_autodocs/readers-extractors.md Gets the current graphics device setting, which can be 'pdf', 'png', or 'svg'. This is useful for optimizing plotting within exercises based on the expected output format. ```APIDOC ## match_exams_device() ### Description Get the current graphics device setting (pdf, png, or svg). ### Returns Character: "pdf", "png", or "svg". NULL if not in weaving context. ### Example ```r # In exercise: <<>>= device <- match_exams_device() if (device == "svg") { # SVG-optimized plotting } else { # Standard plotting } @ ``` ``` -------------------------------- ### Generate PDF exam with custom header and formatting Source: https://github.com/cran/exams.git/blob/master/_autodocs/core-functions.md Example showing how to use `exams2pdf()` with a custom header and specific formatting controls. This includes setting custom text for the header and defining symbols for multiple-choice options. ```r # With custom header and formatting exams2pdf("exercise.Rnw", n = 1, dir = "output", header = c("Course: Statistics 101", "Date: 2025-01-15"), control = list(mchoice.symbol = c(True = "●", False = "○"))) ``` -------------------------------- ### Process Rnw file with Sweave Source: https://github.com/cran/exams.git/blob/master/_autodocs/core-functions.md Example of processing an Rnw file using the default Sweave engine. Ensures quiet output and PDF graphics generation. ```r # Process Rnw file with Sweave xweave("myexercise.Rnw", quiet = TRUE, pdf = TRUE) ``` -------------------------------- ### Ensuring LaTeX Package Installation for helvet Source: https://github.com/cran/exams.git/blob/master/NEWS.md LaTeX templates using \fontfamily{phv} now include \usepackage{helvet} to ensure necessary packages are installed. TinyTeX will automatically install these packages if they are missing upon first use. ```LaTeX \fontfamily{phv} ``` ```LaTeX \usepackage{helvet} ``` -------------------------------- ### Basic xexams() Usage Source: https://github.com/cran/exams.git/blob/master/_autodocs/core-functions.md Demonstrates basic usage of xexams() with default drivers to generate multiple exam replications from specified exercise files. ```r # Basic usage with default drivers exams_list <- xexams(c("exercise1.Rnw", "exercise2.Rnw"), n = 3) ``` -------------------------------- ### Create Exercise Skeleton Files Source: https://github.com/cran/exams.git/blob/master/_autodocs/metadata.md Generate skeleton/template exercise files for various types (schoice, mchoice, numeric, string, cloze). Files can be written to a directory or returned as character strings. ```r exams_skeleton(name = "myexercise", dir = ".", markup = NULL, type = c("schoice", "mchoice", "numeric", "string", "cloze"), writer = TRUE, encoding = "UTF-8") ``` ```r # Create skeleton exercise files in template/ exams_skeleton(name = "template", dir = "templates", type = c("schoice", "mchoice", "numeric")) # Creates: template_schoice.Rnw, template_mchoice.Rnw, template_numeric.Rnw # Get skeleton as text instead of writing skeleton_text <- exams_skeleton(type = "string", writer = FALSE) cat(skeleton_text) ``` -------------------------------- ### print.stress() Source: https://github.com/cran/exams.git/blob/master/_autodocs/stress-testing.md Print method for stress test results, displaying a summary of error/warning counts and example issues. ```APIDOC ## print.stress() ### Description Print method for stress test results. ### Method ```r print(x, ...) ``` ### Parameters #### Path Parameters - **x** (stress) - Required - The stress test result object. #### Query Parameters - **...** - Optional - Additional arguments. ### Output Summary of error/warning counts and example issues. ``` -------------------------------- ### xexams() with Custom PDF Driver Source: https://github.com/cran/exams.git/blob/master/_autodocs/core-functions.md Shows how to use xexams() with a custom driver for PDF output, including Sweave processing, Pandoc transformation, and PDF writing. ```r # Custom driver for PDF output pdfwrite <- make_exams_write_pdf(template = "plain") exams_list <- xexams( file = c("ex1.Rnw", "ex2.Rnw"), n = 2, driver = list( sweave = xweave, read = read_exercise, transform = make_exercise_transform_pandoc(to = "latex"), write = pdfwrite ), dir = "output" ) ``` -------------------------------- ### Using Matrix Input for Exercise Files and Seeds Source: https://github.com/cran/exams.git/blob/master/NEWS.md Provide exercise files and seeds as a matrix to customize the exact selection of exercises in each exam. This feature is currently supported in xexams(), exams2pdf(), exams2html(), exams2nops(), and exams2blackboard(). ```R file can now also be a matrix. The seed can be a matrix of the same dimension. ``` -------------------------------- ### nops_language() Source: https://github.com/cran/exams.git/blob/master/_autodocs/nops-functions.md Sets or gets the language for NOPS output and evaluation messages. Supports language codes or paths to custom DCF files. ```APIDOC ## nops_language() ### Description Set or get the language for NOPS output and evaluation messages. ### Method ```r nops_language(lang = NULL) ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters Table | Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | lang | character or NULL | No | NULL | Language code ("en", "de", etc.) or path to DCF file | ### Returns Character: current language code or language strings (if getting). ### Supported Languages English ("en"), German ("de"), and others via custom DCF files. ### Example ```r # Set German language nops_language("de") # Create custom language file and use it nops_language("path/to/custom.dcf") ``` ``` -------------------------------- ### Create QTI 2.1 item body formatting function Source: https://github.com/cran/exams.git/blob/master/_autodocs/transformers.md Generates a function for formatting exercise content as QTI 2.1 item bodies. Accepts additional arguments for customization. ```R make_itembody_qti21(...) ``` -------------------------------- ### Match Exams Graphics Device Source: https://github.com/cran/exams.git/blob/master/_autodocs/readers-extractors.md Gets the current graphics device setting ('pdf', 'png', or 'svg'). This function is useful for optimizing plotting within exercises based on the expected output format. ```R # In exercise: <<>>= device <- match_exams_device() if (device == "svg") { # SVG-optimized plotting } else { # Standard plotting } @ ``` -------------------------------- ### Full File Path Support on Windows in xexams() Source: https://github.com/cran/exams.git/blob/master/NEWS.md Improved xexams() to correctly handle full file paths to exercise files, ensuring compatibility and functionality on Windows operating systems. ```R xexams() ``` -------------------------------- ### Get Exercise Metadata as List or Data Frame Source: https://github.com/cran/exams.git/blob/master/_autodocs/metadata.md Use `exams_metainfo` to convert exercise metadata from `xexams` output into a list of lists or a data frame. Custom tags can be extracted into separate columns. ```r exams_metainfo(x, class = "exams_metainfo", tags = TRUE, factors = FALSE, ...) ``` ```r # Generate exams exams_list <- xexams("exercise.Rmd", n = 3, nsamp = 2) # Get metadata as list of lists meta_list <- exams_metainfo(exams_list, class = "exams_metainfo") # Get metadata as data frame for easy analysis meta_df <- exams_metainfo(exams_list, class = "data.frame") head(meta_df) # Extract and name custom tags meta_df <- exams_metainfo(exams_list, class = "data.frame", tags = "custom_") ``` -------------------------------- ### Create QTI 1.2 item body formatting function Source: https://github.com/cran/exams.git/blob/master/_autodocs/transformers.md Generates a function for formatting exercise content as QTI 1.2 item bodies. The 'moodle' parameter controls Moodle-specific formatting. ```R make_itembody_qti12(moodle = FALSE, ...) ``` -------------------------------- ### Calculate Points for Numeric Answer within Tolerance Source: https://github.com/cran/exams.git/blob/master/_autodocs/evaluation.md Calculates points for a numeric answer, checking if it falls within a specified tolerance range. This example shows how to use the tolerance parameter for 'num' type questions. ```r points <- ev$pointsum( correct = 100, answer = 101, tolerance = 5, type = "num" ) ``` -------------------------------- ### xexams() with Matrix Specification Source: https://github.com/cran/exams.git/blob/master/_autodocs/core-functions.md Illustrates using a matrix to specify fixed exercise selection for xexams(), allowing for precise control over which exercises are included in each exam. ```r # Matrix specification for fixed exercise selection file_matrix <- matrix(c("ex1", "ex2", "ex3", "ex4"), nrow = 2, ncol = 2) exams_list <- xexams(file_matrix, n = 10, dir = "exams") ``` -------------------------------- ### exams_skeleton() Source: https://github.com/cran/exams.git/blob/master/_autodocs/metadata.md Creates a skeleton or template exercise file for various exercise types. It can generate files in a specified directory or return the skeleton content as text. ```APIDOC ## exams_skeleton() ### Description Create a skeleton/template exercise file or set of exercises. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **name** (character) - Optional - Default: "myexercise" - Base name for exercise file(s) - **dir** (character) - Optional - Default: "." - Output directory - **markup** (character or NULL) - Optional - Default: NULL - Exercise markup: "latex" (*.Rnw) or "markdown" (*.Rmd). Auto-chosen if NULL - **type** (character) - Optional - Default: "schoice" - Exercise type(s) to create. Can be vector for multiple - **writer** (logical) - Optional - Default: TRUE - Whether to write files (TRUE) or return as character (FALSE) - **encoding** (character) - Optional - Default: "UTF-8" - File encoding ### Returns Invisible NULL (if `writer=TRUE`), or character vector with skeleton content. ### Generated Files: - For each type, creates file: `[name]_[type].Rnw` or `[name]_[type].Rmd` - Each file contains exercise template with appropriate structure ### Example ```r # Create skeleton exercise files in template/ exams_skeleton(name = "template", dir = "templates", type = c("schoice", "mchoice", "numeric")) # Creates: template_schoice.Rnw, template_mchoice.Rnw, template_numeric.Rnw # Get skeleton as text instead of writing skeleton_text <- exams_skeleton(type = "string", writer = FALSE) cat(skeleton_text) ``` ``` -------------------------------- ### Convert LaTeX to Image Source: https://github.com/cran/exams.git/blob/master/_autodocs/transformers.md Render LaTeX code to image files (PNG, SVG, PDF) using the `tex2image` function. This requires LaTeX and ImageMagick installations and allows specifying output format, dimensions, and included LaTeX packages. ```r tex2image(tex, format = "png", width = 4, height = 4, dir = ".", name = NULL, idir = ".", packages = NULL, tikz = FALSE, density = 150, tol = 0.1, ...) ``` ```r # Convert single LaTeX expression img <- tex2image("$\int_0^\infty e^{-x} dx = 1$", name = "integral") # Generates: integral.png ``` -------------------------------- ### Create Moodle question formatting function (XML) Source: https://github.com/cran/exams.git/blob/master/_autodocs/transformers.md Generates a function for formatting exercise content as Moodle XML questions. The 'moodle' parameter controls Moodle version compatibility. ```R make_question_moodle(moodle = FALSE, ...) ``` -------------------------------- ### xexams() Source: https://github.com/cran/exams.git/blob/master/_autodocs/core-functions.md Generates exams from exercise files using pluggable drivers. It supports various options for file input, replication, sampling, driver configuration, output directories, and random seed control. ```APIDOC ## xexams() ### Description Extensible exam generation framework. The primary interface for generating exams from exercise files with pluggable drivers for sweaving, reading, transforming, and writing. ### Function Signature ```r xexams(file, n = 1L, nsamp = NULL, driver = list(sweave = NULL, read = NULL, transform = NULL, write = NULL), dir = ".", edir = NULL, tdir = NULL, sdir = NULL, verbose = FALSE, points = NULL, seed = NULL, rds = FALSE, ...) ``` ### Parameters #### Path Parameters - **file** (character, list, or matrix) - Yes - Exercise file(s). Can be a character vector of file names, a list where each element is a vector of files, or a matrix specifying exercise selection. - **n** (integer) - No - 1L - Number of exam replications to generate. - **nsamp** (integer vector) - No - NULL - Number of exercises to sample from each element of `file`. Recycled to match length of `file`. - **driver** (list) - No - list(sweave=NULL, read=NULL, transform=NULL, write=NULL) - List with named function elements: `sweave` (file processing), `read` (reading compiled files), `transform` (optional transformation), `write` (optional output writing). - **dir** (character or NULL) - No - "." - Output directory path. Required if writing output. - **edir** (character or NULL) - No - NULL - Exercise directory path. If NULL, current working directory used. - **tdir** (character or NULL) - No - NULL - Temporary work directory. If NULL, a temporary directory is created. - **sdir** (character or NULL) - No - NULL - Supplement directory for storing generated images/files. - **verbose** (logical) - No - FALSE - If TRUE, print progress information. - **points** (numeric vector or NULL) - No - NULL - Points per exercise. Recycled to match number of exercises or length 1. - **seed** (logical, integer matrix, or NULL) - No - NULL - Random seed control. If TRUE, random matrix generated. If matrix, must be n × m (exams × exercises). - **rds** (logical or character) - No - FALSE - If TRUE or character filename, save exam list as RDS file in output directory. - **...** (—) - No - — - Additional arguments passed to driver functions. ### Returns List of length n where each element is a list of exercises with metadata, question/solution text, and supplement file paths. ### Example ```r # Basic usage with default drivers exams_list <- xexams(c("exercise1.Rnw", "exercise2.Rnw"), n = 3) # Custom driver for PDF output pdfwrite <- make_exams_write_pdf(template = "plain") exams_list <- xexams( file = c("ex1.Rnw", "ex2.Rnw"), n = 2, driver = list( sweave = xweave, read = read_exercise, transform = make_exercise_transform_pandoc(to = "latex"), write = pdfwrite ), dir = "output" ) # Matrix specification for fixed exercise selection file_matrix <- matrix(c("ex1", "ex2", "ex3", "ex4"), nrow = 2, ncol = 2) exams_list <- xexams(file_matrix, n = 10, dir = "exams") ``` ``` -------------------------------- ### Calculate Points for Multiple-Choice Answer Source: https://github.com/cran/exams.git/blob/master/_autodocs/evaluation.md Calculates points for a multiple-choice question where the student got 2 out of 4 items correct. This example demonstrates how pointsum is used with boolean vectors for correct and given answers, specifying the 'mchoice' type. ```r points <- ev$pointsum( correct = c(TRUE, FALSE, TRUE, FALSE), answer = c(TRUE, FALSE, FALSE, FALSE), type = "mchoice" ) ``` -------------------------------- ### Create Grasple platform export writing function Source: https://github.com/cran/exams.git/blob/master/_autodocs/transformers.md Generates a function for writing exercise data in Grasple format. Accepts additional arguments for customization. ```R make_exams_write_grasple(...) ``` -------------------------------- ### answerlist() Source: https://github.com/cran/exams.git/blob/master/_autodocs/formatters.md Generates a formatted answer list block suitable for inclusion in exercises, supporting LaTeX and Markdown output. ```APIDOC ## answerlist() ### Description Generate formatted answer list block for inclusion in exercises. ### Method ```r answerlist(..., sep = ". ", markup = NULL, write = TRUE) ``` ### Parameters #### Arguments - **...** - Required - Answer items as separate arguments - **sep** (character) - Optional - Separator between items - **markup** (character or NULL) - Optional - Output format (auto-detected if NULL from xweave context) - **write** (logical) - Optional - If TRUE, write output; if FALSE return as character vector ### Returns Character vector with formatted answer list block. If `write=TRUE`, also prints to output and returns invisibly. ### Output format - LaTeX: `\begin{answerlist}` ... `\end{answerlist}` with `\item` entries - Markdown: Formatted list with markdown section headers ### Example ```r # In exercise file: <<>>= answerlist("Option A", "Option B", "Option C") @ # Returns/prints: # \begin{answerlist} # \item Option A. # \item Option B. # \item Option C. # \end{answerlist} ``` ``` -------------------------------- ### read_exercise() Source: https://github.com/cran/exams.git/blob/master/_autodocs/readers-extractors.md Reads a compiled exercise file (.tex) and extracts question, solution, and metadata. It can optionally shuffle answer options. ```APIDOC ## read_exercise() ### Description Reads a compiled exercise file (`.tex`) and extracts question, solution, and metadata. It can optionally shuffle answer options. ### Method Not applicable (R function) ### Parameters #### Path Parameters - **file** (character) - Required - Path to compiled exercise file (`.tex` or `.rtex`) #### Query Parameters - **markup** (character or NULL) - Optional - Markup language: "latex" or "markdown". Auto-detected from file extension if NULL - **exshuffle** (logical, numeric, or NULL) - Optional - Shuffle answer options. If numeric, maximum number of options to include ### Returns List with elements: - `question` - character vector with question text - `questionlist` - character vector with answer options (for choice questions) - `solution` - character vector with solution text - `solutionlist` - character vector with solution options (for choice questions) - `metainfo` - list with exercise metadata ### Request Example ```r # Read a compiled exercise exercise <- read_exercise("myexercise.tex") cat(exercise$question) cat("Answers:", paste(exercise$questionlist, collapse="; ")) # With shuffling exercise <- read_exercise("quiz.tex", exshuffle = 3) ``` ``` -------------------------------- ### make_question_moodle Source: https://github.com/cran/exams.git/blob/master/_autodocs/transformers.md Creates a Moodle question formatting function for XML generation. ```APIDOC ## make_question_moodle() ### Description Create Moodle question formatting function for XML generation. ### Method ```r make_question_moodle(moodle = FALSE, ...) ``` ### Parameters #### Path Parameters - **moodle** (logical) - Optional - Default: FALSE - Moodle version/compatibility flag. - **...** (—) - Optional - Additional arguments. ### Returns Function for formatting exercise content as Moodle XML questions. ``` -------------------------------- ### Create HTML Transformation Function Source: https://github.com/cran/exams.git/blob/master/_autodocs/transformers.md Use `make_exercise_transform_html` to create a function for converting exercise content to HTML. It supports various converters like 'ttm', 'tth', 'pandoc', and 'tex2image', with options for base64 embedding of images. ```r make_exercise_transform_html(converter = c("ttm", "tth", "pandoc", "tex2image"), base64 = TRUE, options = NULL, ...) ``` ```r # Create HTML transformer with MathML math html_trans <- make_exercise_transform_html(converter = "pandoc-mathml") # Use in exams2html exams2html("exercise.Rmd", dir = "html", transform = html_trans) # Base64 embed images html_trans <- make_exercise_transform_html(base64 = TRUE) # Custom image types only html_trans <- make_exercise_transform_html(base64 = c("png", "svg")) ``` -------------------------------- ### Error Handling with try-error Class Source: https://github.com/cran/exams.git/blob/master/_autodocs/types.md Demonstrates how to check if an object is a `try-error` to handle errors within stress test results. ```r if(inherits(obj, "try-error")) { # Handle error } ``` -------------------------------- ### Evaluate Answers Programmatically Source: https://github.com/cran/exams.git/blob/master/_autodocs/README.md Sets up an evaluation scheme for exams, allowing for partial credit and no negative marking. Includes functions to check individual answers and calculate total points. ```r ev <- exams_eval(partial = TRUE, negative = FALSE) # Check a multiple-choice answer result <- ev$checkanswer( correct = c(TRUE, FALSE, TRUE), answer = c(TRUE, FALSE, FALSE), type = "mchoice" ) # Result: c(1, 0, -1) under partial credit # Calculate points points <- ev$pointsum( correct = c(TRUE, FALSE, TRUE), answer = c(TRUE, FALSE, FALSE), type = "mchoice" ) ``` -------------------------------- ### Create Moodle 2.3+ compatible question formatting function Source: https://github.com/cran/exams.git/blob/master/_autodocs/transformers.md Generates a function specifically for Moodle 2.3+ compatible question formatting. Accepts additional arguments for customization. ```R make_question_moodle23(...) ``` -------------------------------- ### make_question_moodle23 Source: https://github.com/cran/exams.git/blob/master/_autodocs/transformers.md Creates a Moodle 2.3+ compatible question formatting function. ```APIDOC ## make_question_moodle23() ### Description Create Moodle 2.3+ compatible question formatting function. ### Method ```r make_question_moodle23(...) ``` ### Parameters #### Path Parameters - **...** (—) - Optional - Additional arguments. ### Returns Function for Moodle 2.3+ specific question formatting. ``` -------------------------------- ### List of Stress Test Results Source: https://github.com/cran/exams.git/blob/master/_autodocs/types.md Demonstrates creating a list of stress test results for multiple exercises and checking its class. ```r result <- stresstest_exercise(c("ex1.Rnw", "ex2.Rnw")) class(result) # [1] "stress.list" "stress" "list" ``` -------------------------------- ### Create Evaluation Object with Custom Settings Source: https://github.com/cran/exams.git/blob/master/_autodocs/evaluation.md Creates an evaluation object with custom settings for partial credit, penalty for wrong answers, and the rule for point calculation. ```r ev <- exams_eval(partial = FALSE, negative = TRUE, rule = "all") ``` -------------------------------- ### Configuring LaTeX Conversion in exams Source: https://github.com/cran/exams.git/blob/master/NEWS.md Set options(exams_tex = "tools") to enforce the use of tools::texi2dvi() for PDF conversion, overriding the default tinytex::latexmk() when tinytex is available. This is useful for maintaining previous conversion behavior. ```R options(exams_tex = "tools") ``` -------------------------------- ### make_exams_write_grasple Source: https://github.com/cran/exams.git/blob/master/_autodocs/transformers.md Creates a Grasple platform export writing function. ```APIDOC ## make_exams_write_grasple() ### Description Create Grasple platform export writing function. ### Method ```r make_exams_write_grasple(...) ``` ### Parameters #### Path Parameters - **...** (—) - Optional - Additional arguments. ### Returns Function for writing exercise data in Grasple format. ``` -------------------------------- ### make_itembody_qti12 Source: https://github.com/cran/exams.git/blob/master/_autodocs/transformers.md Creates a QTI 1.2 item body formatting function for question presentation. ```APIDOC ## make_itembody_qti12() ### Description Create QTI 1.2 item body formatting function for question presentation. ### Method ```r make_itembody_qti12(moodle = FALSE, ...) ``` ### Parameters #### Path Parameters - **moodle** (logical) - Optional - Default: FALSE - Moodle-specific formatting. - **...** (—) - Optional - Additional arguments. ### Returns Function for formatting exercise content as QTI 1.2 item bodies. ``` -------------------------------- ### exams2html() Source: https://github.com/cran/exams.git/blob/master/_autodocs/core-functions.md Generate HTML exams from exercise files. ```APIDOC ## exams2html() ### Description Generate HTML exams from exercise files. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **file** (character, list, or matrix) - Required - Exercise file(s) - **n** (integer) - Optional - Number of exam replications - **nsamp** (integer vector) - Optional - Samples per file element - **dir** (character) - Optional - Output directory - **template** (character) - Optional - HTML template file - **name** (character or NULL) - Optional - Output file name base - **quiet** (logical) - Optional - Suppress processing output - **edir** (character or NULL) - Optional - Exercise directory - **tdir** (character or NULL) - Optional - Temporary directory - **sdir** (character or NULL) - Optional - Supplement directory - **verbose** (logical) - Optional - Print progress - **rds** (logical or character) - Optional - Save exam list as RDS - **question** (character) - Optional - HTML header before question text - **solution** (character) - Optional - HTML header before solution text - **mathjax** (logical or NULL) - Optional - Include MathJax script for math rendering - **resolution** (numeric) - Optional - Figure resolution in DPI - **width** (numeric) - Optional - Figure width in inches - **height** (numeric) - Optional - Figure height in inches - **svg** (logical) - Optional - Use SVG graphics instead of PNG - **encoding** (character) - Optional - File encoding - **envir** (environment or NULL) - Optional - R evaluation environment - **engine** (character or NULL) - Optional - Rendering engine: "sweave" or "knitr" - **converter** (character or NULL) - Optional - Markup converter: "pandoc" or "ttm" (default for .Rnw) - **seed** (numeric or matrix or NULL) - Optional - Random seed - **exshuffle** (logical, numeric, or NULL) - Optional - Shuffle answer options - **...** (—) - Optional - Additional arguments to converter ### Returns Invisible list of exam objects. ### Note For single exam, HTML file automatically opens in browser. ### Example ```r exams2html(c("ex1.Rmd", "ex2.Rmd"), n = 2, dir = "html_exams", template = "plain", mathjax = TRUE) ``` ``` -------------------------------- ### make_exams_write_html Source: https://github.com/cran/exams.git/blob/master/_autodocs/transformers.md Creates an HTML writing/output function for xexams. ```APIDOC ## make_exams_write_html() ### Description Create HTML writing/output function for xexams. ### Method ```r make_exams_write_html(template = "plain", name = NULL, question = "

Question

", solution = "

Solution

", mathjax = FALSE) ``` ### Parameters #### Path Parameters - **template** (character or NULL) - Optional - Default: "plain" - HTML template file name. - **name** (character or NULL) - Optional - Default: NULL - Output file name base. - **question** (character) - Optional - Default: "

Question

" - HTML header for question section. - **solution** (character) - Optional - Default: "

Solution

" - HTML header for solution section. - **mathjax** (logical) - Optional - Default: FALSE - Include MathJax script for mathematics. ### Returns Function suitable for `driver$write` in xexams. ``` -------------------------------- ### make_exercise_transform_html() Source: https://github.com/cran/exams.git/blob/master/_autodocs/transformers.md Creates an HTML transformation function for exercises. It supports various conversion methods like ttm, tth, pandoc, and tex2image, with options for base64 image embedding and converter-specific settings. ```APIDOC ## make_exercise_transform_html() ### Description Create HTML transformation function for exercises. ### Method `make_exercise_transform_html(converter = c("ttm", "tth", "pandoc", "tex2image"), base64 = TRUE, options = NULL, ...)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **converter** (character) - Optional - Default: "ttm" - Conversion method: "ttm" (tth with math markup), "tth" (tth), "pandoc" (pandoc converter), "tex2image" (convert LaTeX to images) - **base64** (logical, character, or NULL) - Optional - Default: TRUE - Embed images as base64 data URIs. If FALSE, reference files. If NULL or character vector, specify file types (e.g., c("png", "jpg")) - **options** (character or NULL) - Optional - Default: NULL - Converter-specific options (e.g., "--mathml" for pandoc) - **...** (—) - Optional - Additional arguments to converter ### Returns Function for transforming exercise objects. Input: exercise list (from read_exercise). Output: modified exercise with HTML content. ### Supported Converters - **ttm** - Requires `tth` package. Fast conversion with MathML math markup - **tth** - Requires `tth` package. Conversion with HTML math markup - **pandoc** - Requires `rmarkdown` package with pandoc. Feature-rich conversion - **pandoc-mathml** - Pandoc with MathML math - **pandoc-mathjax** - Pandoc with MathJax - **tex2image** - Render LaTeX as images (PNG/SVG) ### Example ```r # Create HTML transformer with MathML math html_trans <- make_exercise_transform_html(converter = "pandoc-mathml") # Use in exams2html exams2html("exercise.Rmd", dir = "html", transform = html_trans) # Base64 embed images html_trans <- make_exercise_transform_html(base64 = TRUE) # Custom image types only html_trans <- make_exercise_transform_html(base64 = c("png", "svg")) ``` ``` -------------------------------- ### make_exams_write_pdf() Source: https://github.com/cran/exams.git/blob/master/_autodocs/core-functions.md Factory function to create a PDF writer function for use with xexams(). ```APIDOC ## make_exams_write_pdf() ### Description Factory function to create a PDF writer function for use with xexams(). ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **template** (character) - Optional - LaTeX template file name(s) - **inputs** (character vector or NULL) - Optional - Additional input files - **header** (list or NULL) - Optional - Header content - **usepackage** (character vector or NULL) - Optional - LaTeX packages to include - **name** (character or NULL) - Optional - Output file name base - **encoding** (character) - Optional - File encoding - **quiet** (logical) - Optional - Suppress LaTeX output - **control** (list or NULL) - Optional - Formatting control - **texdir** (character or NULL) - Optional - Directory for TeX files - **texengine** (character) - Optional - LaTeX processing engine ### Returns Function suitable for use as `driver$write` in xexams(). ### Example ```r writer <- make_exams_write_pdf(template = "mysolution", name = "exam") exams_list <- xexams( "exercise.Rnw", n = 2, driver = list(write = writer), dir = "output" ) ``` ``` -------------------------------- ### Generate Formatted Answer List Source: https://github.com/cran/exams.git/blob/master/_autodocs/formatters.md Creates a formatted answer list block suitable for inclusion in exercises. It can output in LaTeX or Markdown format, with customizable separators. ```r # In exercise file: <<>>= answerlist("Option A", "Option B", "Option C") @ # Returns/prints: # \begin{answerlist} # \item Option A. # \item Option B. # \item Option C. # \end{answerlist} ``` -------------------------------- ### Create ARSnova/Particify export writing function Source: https://github.com/cran/exams.git/blob/master/_autodocs/transformers.md Generates a function for writing exercise data in ARSnova/Particify format. Accepts additional arguments for customization. ```R make_exams_write_arsnova(...) ``` -------------------------------- ### Create Blackboard item body formatting function Source: https://github.com/cran/exams.git/blob/master/_autodocs/transformers.md Generates a function for formatting exercise content specifically for the Blackboard LMS. Accepts additional arguments for customization. ```R make_itembody_blackboard(...) ``` -------------------------------- ### Read Compiled Exercise File Source: https://github.com/cran/exams.git/blob/master/_autodocs/readers-extractors.md Reads a compiled exercise file (.tex or .rtex) and extracts its question, answer options, solution, and metadata. Supports shuffling answer options. ```r read_exercise(file, markup = NULL, exshuffle = NULL) ``` ```r # Read a compiled exercise exercise <- read_exercise("myexercise.tex") cat(exercise$question) cat("Answers:", paste(exercise$questionlist, collapse="; ")) # With shuffling exercise <- read_exercise("quiz.tex", exshuffle = 3) ``` -------------------------------- ### Include Exercise Supplement Source: https://github.com/cran/exams.git/blob/master/_autodocs/readers-extractors.md Includes external files (like images or data files) as supplements to an exercise. Specify the file path and optionally a destination directory within the supplements folder. ```R # In exercise: # Reference external image include_supplement("plot.png") ``` -------------------------------- ### exams() Source: https://github.com/cran/exams.git/blob/master/_autodocs/core-functions.md Legacy version 1 interface for generating PDF exams. Maintained for backward compatibility but exams2pdf() recommended. ```APIDOC ## exams() Legacy version 1 interface for generating PDF exams. Maintained for backward compatibility but exams2pdf() recommended. ```r exams(file, n = 1, nsamp = NULL, dir = NULL, template = "plain", inputs = NULL, header = list(Date = Sys.Date()), name = NULL, quiet = TRUE, edir = NULL, tdir = NULL, control = NULL) ``` | Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | file | character or list | Yes | — | Exercise file(s) or lists of files | | n | integer | No | 1 | Number of exam replications | | nsamp | integer vector | No | NULL | Number of samples per file element | | dir | character or NULL | No | NULL | Output directory. Required if n > 1 or multiple templates | | template | character | No | "plain" | LaTeX template file name (without `.tex`) | | inputs | character vector or NULL | No | NULL | Additional LaTeX input files | | header | list | No | list(Date = Sys.Date()) | Header metadata as name=value list | | name | character or NULL | No | NULL | Output file name base | | quiet | logical | No | TRUE | Suppress Sweave output | | edir | character or NULL | No | NULL | Exercise directory | | tdir | character or NULL | No | NULL | Temporary work directory | | control | list or NULL | No | NULL | Output formatting control list with elements `mchoice.print` and `mchoice.symbol` | **Returns:** List of lists containing exercise metadata (type, solution, string representation). Class `exams_metainfo`. **Note:** This is the outdated version 1 interface. Use exams2pdf() instead. **Source:** R/exams.R:1-267 ``` -------------------------------- ### Create PDF Writer Function for xexams Source: https://github.com/cran/exams.git/blob/master/_autodocs/core-functions.md Use this factory function to create a PDF writer for `xexams()`. Specify LaTeX template, input files, and other formatting options. ```r make_exams_write_pdf(template = "plain", inputs = NULL, header = NULL, usepackage = NULL, name = NULL, encoding = "UTF-8", quiet = TRUE, control = NULL, texdir = NULL, texengine = "pdflatex") ``` ```r writer <- make_exams_write_pdf(template = "mysolution", name = "exam") exams_list <- xexams( "exercise.Rnw", n = 2, driver = list(write = writer), dir = "output" ) ``` -------------------------------- ### Stress Test Result Object Source: https://github.com/cran/exams.git/blob/master/_autodocs/types.md Shows how to create a stress test result object and use its summary, print, and plot methods. ```r result <- stresstest_exercise("ex.Rnw", n = 100) class(result) # [1] "stress" summary(result) plot(result) ``` -------------------------------- ### Illustrating Random True/False Item Selection Source: https://github.com/cran/exams.git/blob/master/NEWS.md New exercise 'capitals.Rmd'/'Rnw' demonstrates selecting a random number of true/false items from a list. It supports switching between mchoice and schoice and illustrates UTF-8 encoding needs for Rmd vs. ASCII/LaTeX for Rnw. ```R capitals.Rmd ``` ```R capitals.Rnw ``` -------------------------------- ### Setting Random Seeds for Individual Exercises Source: https://github.com/cran/exams.git/blob/master/NEWS.md Enable custom exercise selection by setting random seeds for each individual exercise within an exam. Currently supported in xexams(), exams2pdf(), exams2html(), exams2nops(), and exams2blackboard(). ```R seed is not only set prior to weaving but also to reading the exercise. ``` -------------------------------- ### Create LOPS (WU exam server) writing function Source: https://github.com/cran/exams.git/blob/master/_autodocs/transformers.md Generates a function for writing exercise data in LOPS (WU exam server) format. Accepts additional arguments for customization. ```R make_exams_write_lops(...) ``` -------------------------------- ### print.stress.summary() Source: https://github.com/cran/exams.git/blob/master/_autodocs/stress-testing.md Print method for stress test summary, displaying formatted summary statistics. ```APIDOC ## print.stress.summary() ### Description Print method for stress test summary. ### Method ```r print(x, ...) ``` ### Parameters #### Path Parameters - **x** (stress.summary) - Required - The stress test summary object. #### Query Parameters - **...** - Optional - Additional arguments. ### Output Formatted summary statistics table. ``` -------------------------------- ### include_supplement() Source: https://github.com/cran/exams.git/blob/master/_autodocs/readers-extractors.md Includes external files (like images or data files) as supplements to an exercise. It returns the character path to the included file. ```APIDOC ## include_supplement() ### Description Include external files (images, data files) as exercise supplements. ### Parameters #### Path Parameters - **file** (character) - Required - File path to include - **dir** (character or NULL) - Optional - Destination directory within supplements (if NULL, auto-determined) (Default: NULL) ### Returns Character path to included file. ### Example ```r # In exercise: # Reference external image include_supplement("plot.png") ``` ``` -------------------------------- ### Generate SVG graphics with knitr Source: https://github.com/cran/exams.git/blob/master/_autodocs/core-functions.md Shows how to generate SVG graphics from an exercise file using knitr. The engine is specified as 'knitr' and SVG output is enabled. ```r # Generate SVG graphics xweave("exercise.Rnw", svg = TRUE, engine = "knitr") ```