Package 'knitexercise'

Title: Knit Exercise Questions and Solutions from the Same R Markdown Document
Description: Provides a function to knit questions and solutions documents from the same R Markdown document.
Authors: Tom Palmer [aut, cre]
Maintainer: Tom Palmer <[email protected]>
License: GPL-3
Version: 0.4.1
Built: 2024-10-26 05:11:24 UTC
Source: https://github.com/remlapmot/knitexercise

Help Index


knitexercise: Knit exercise questions and solutions from the same R Markdown document

Description

This package provides a custom knit function, knit_exercise(), which sets the global chunk option include. This is controlled by setting the solutions parameter in the YAML header of the R Markdown document.

Details

To generate your output document with questions set solutions: FALSE. For your output document containing the solutions set solutions: TRUE.

Your YAML header should look something like the following.

---
title: My Title
author: My Name
params:
  solutions: FALSE
knit: knitexercise::knit_exercise
output: html_document
---

For your solutions output document -solutions is added to the filename before the file extension.

There is a template R Markdown document which you can open through the following menu in RStudio: File | New File | R Markdown... | From Template, or with the following code.

rmarkdown::draft(
  "my_exercise.Rmd",
  template = "exercise_template",
  package = "knitexercise"
)

Author(s)

Maintainer: Tom Palmer [email protected] (ORCID)

See Also

Useful links:


Custom Knit function for RStudio

Description

This function adds -solutions to the end of the filename before the file extension of the output document from your R Markdown document when rendered by clicking the Knit button in RStudio and when you have set solutions: TRUE in the ⁠params:⁠ field of your YAML header.

Usage

knit_exercise(inputFile, encoding)

Arguments

inputFile

The name of the R Markdown file to be rendered.

encoding

As per rmarkdown::render_site() this is ignored. The encoding is always assumed to be UTF-8.

Details

This function is used with the ⁠knit:⁠ field of the YAML header of an R Markdown file. For example, if you want pdf output the YAML header would be as follows.

---
title: My Title
params:
  solutions: TRUE
output: pdf_document
knit: knitexercise::knit_exercise
---

This function also sets the global chunk option include to the value specified by ⁠solutions:⁠, i.e. set solutions: FALSE for your questions document and solutions: TRUE for your solutions document.

See Also

This function is modified from the following example by Yihui Xie https://bookdown.org/yihui/rmarkdown-cookbook/custom-knit.html.

Examples

## Not run: 
# To launch the R Markdown template run
rmarkdown::draft(
  'exercise.Rmd',
   template = 'exercise_template',
   package = 'knitexercise')

## End(Not run)