Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor tutorial knitr hooks and set them in the tutorial format #599

Merged
merged 6 commits into from
Oct 15, 2021

Conversation

gadenbuie
Copy link
Member

tutorial_knitr_options() now prepares a list of knitr options with the knitr options and hooks that are used during the tutorial pre-render. This list is in the same format as the knitr options expected by rmarkdown::output_format() so we can set the knitr options directly in the tutorial output format.

This ensures that the hooks are set for each rmarkdown::render() call. Previously, by only relying on .onAttach(), these hooks might be reset at the end of the first render() and wouldn't be re-installed for subsequent renders, resulting in the behavior seen in #598. I haven't removed the .onAttach() mechanism because it is still useful for catching learnr component usage outside of the learnr::tutorial() format.

Fixes #598

`tutorial_knitr_options()` now prepares a list of knitr options with the knitr options and hooks that are used during the tutorial pre-render. This list is in the same format as the knitr options expected by `rmarkdown::output_format()` so we can set the knitr options directly in the `tutorial` output format.

This ensures that the hooks are set for each `rmarkdown::render()` call. Previously, by only relying on `.onAttach()`, these hooks might be reset at the end of the first `render()` and wouldn't be re-installed for subsequent renders, resulting in the behavior seen in #598. I haven't removed the `.onAttach()` mechanism because it is still useful for catching learnr component usage outside of the `learnr::tutorial()` format.
This is now redundant for `learnr::tutorial` documents, but required for tutorials that don't use the tutorial format
@gadenbuie gadenbuie changed the title Refactor tutorial knitr hooks so they can be set in the tutorial format Refactor tutorial knitr hooks and set them in the tutorial format Oct 15, 2021
@gadenbuie gadenbuie merged commit 27f2854 into master Oct 15, 2021
@gadenbuie gadenbuie deleted the knitr-hooks-in-format branch October 15, 2021 19:53
@gadenbuie
Copy link
Member Author

@dbkmsu can you please open a new issue with a reproducible example?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Code boxes don't run if opened for a second time
2 participants