include_exercise: Insert an exercise from a file

View source: R/exercises.R

include_exerciseR Documentation

Insert an exercise from a file

Description

Each exercise is contained in its own file, with a unique ID. This function reads the file for that ID, knits the contents, and returns the knitted contents. Typically this will be used to insert the exercise into an Rmd file. If not specified, argument show_answer will be read from options("show_answer").

Usage

include_exercise(
  id,
  show_answer = getOption("show_exercise", TRUE),
  verbose = TRUE,
  directory = "Exercises",
  prob_name = "Problem XX",
  format = ifelse(knitr::is_latex_output(), "latex", "html")
)

Arguments

id

the unique ID of the exercise file. Don't include the file type suffix ".Rmd" in the id.

show_answer

if TRUE, include the answer comments from the file.

verbose

Include the YAML information

directory

the directory where the exercise file is to be found

prob_name

Character string naming the problem, e.g. "Prob 1.3"

Details

When output is in html, use the answer-fragment class in CSS to format the answers.

Examples

the_testing_dir <- system.file("Test_exercises", package = "SDSdata")
include_exercise("beech-run-mug", directory = the_testing_dir, format = "latex")


dtkaplan/SDSdata documentation built on June 28, 2022, 8:09 a.m.