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

feature: make all solution chunks foldable and folded by default #68

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dlaehnemann
Copy link

I used this book to give an intro into R course, and it was very useful to teach both people without any prior programming or R experience, and those that have already worked a bit in R. It enabled self-paced studying, with help among participants and by the instructor. So thanks a lot for this resource!

That said, one major feedback I got, was that it was annoying to always already see the solutions to the exercises. It apparently prevented people from sitting down and thinking the exercise through, before evaluating whether they got it right. As I might want to come back to using this book and as others will probably have a similar problem, I spent the past week looking around for a way to get all ```{solution} code chunks foldable and folded by default. And here it is:

One can wrap all the respective code chunks in <details></details> html tags. To automated this across all documents, I use the suggestion for such <details> elements from the RMarkdown cookbook, and get the respective code snippet to be appended to every document in the book by using the html_document includes: tag after_body:. This works, when compiling the book locally with Rscript -e 'bookdown::render_book("index.rmd")' with knitr_1.42 and bookdown_0.32.

A more thorough solution would probably change the solution chunk engine in bookdown to include a configuration option for the generic code folding functionality in RMarkdown html_document rendering. But I couldn't figure out the respective Lua code. And this solution here works, with minimal changes.

@dlaehnemann
Copy link
Author

P.S.: I did not include the recompiled book, to have the changes visible more clearly. And I'm not sure, how deployment of the book actually works (manual or via Travis or some other mechanism?).

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.

None yet

1 participant