Closed rkb965 closed 1 year ago
Hi, you can achieve this by setting class.message
and class.warning
options, e.g.,
---
title: "Test"
output:
html_document:
code_folding: show
---
```{r, setup, include=FALSE}
knitr::opts_chunk$set(class.message='foldable fold-hide', class.warning='foldable fold-hide')
message('Hello message!')
warning('Hello warning!')
References:
- https://bookdown.org/yihui/rmarkdown-cookbook/fold-show.html
- https://yihui.org/knitr/options/
Wow, thanks @yihui ! It looks like that has existed for quite a long time without me ever running across it. Thank you!
btw -- I see it described clearly in your second link but it wasn't clear to me from the linked bit of the cookbook that class.message and class.warning existed (it is absolutely mentioned here: https://bookdown.org/yihui/rmarkdown-cookbook/attr-output.html#attr-output)
I'm going to be using this extensively. Thank you for the wonderful package and documentation, and thank you for taking the time to respond to this question.
You are welcome! Thank you for the patience in the long waiting! I understand that sometimes it's not easy to connect the dots. To be honest, even I was not aware of this solution in the beginning. I thought it was a new feature that I would have to implement, but after a while I suddenly recalled @atusy's foresight rstudio/rmarkdown#1835.
The solution has a little imperfection, which will be improved by https://github.com/rstudio/rmarkdown/pull/2489.
This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.
Hi all -- thank you for your wonderful work on
knitr
Feature request: Could you add
message-folding
andwarning-folding
options, in the vein ofcode-folding
?Justification: I use knitr/rmarkdown pretty exclusively for sharing analyses with colleagues. I'd like to be able to show a relatively clean document with the option to expand messages/warnings for input from my collaborators. When I leave messages/warnings in, they can be overwhelming and distracting from the primary output, but when I remove them, I miss the opportunity for some useful input (eg on things like model fit messages or tidylog messages about dropped observations, etc). I'd appreciate the opportunity to generally fold them and expand as relevant in a discussion.
Thank you so much for considering this!
By filing an issue to this repo, I promise that
xfun::session_info('knitr')
. I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version:remotes::install_github('yihui/knitr')
.I understand that my issue may be closed if I don't fulfill my promises.