| 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] (ORCID: <https://orcid.org/0000-0003-4655-4511>) |
| Maintainer: | Tom Palmer <[email protected]> |
| License: | GPL-3 |
| Version: | 0.4.3 |
| Built: | 2026-05-14 19:38:43 UTC |
| Source: | https://github.com/remlapmot/knitexercise |
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.
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" )
Maintainer: Tom Palmer [email protected] (ORCID)
Authors:
Tom Palmer [email protected] (ORCID)
Useful links:
Report bugs at https://github.com/remlapmot/knitexercise/issues
This function adds -questions/-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: FALSE/solutions: TRUE in the params: field
of your YAML header.
knit_exercise(inputFile, encoding)knit_exercise(inputFile, encoding)
inputFile |
The name of the R Markdown file to be rendered. |
encoding |
As per |
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.
This function is modified from the following example by Yihui Xie https://bookdown.org/yihui/rmarkdown-cookbook/custom-knit.html.
## Not run: # To launch the R Markdown template run rmarkdown::draft( 'exercise.Rmd', template = 'exercise_template', package = 'knitexercise') ## End(Not run)## Not run: # To launch the R Markdown template run rmarkdown::draft( 'exercise.Rmd', template = 'exercise_template', package = 'knitexercise') ## End(Not run)