distill icon indicating copy to clipboard operation
distill copied to clipboard

collapse = TRUE option not available

Open rkbauer opened this issue 4 years ago • 3 comments
trafficstars

I would like to collapse the code chunks and related outputs via the collapse=TRUE argument as it is shown here: https://bookdown.org/yihui/rmarkdown-cookbook/opts-collapse.html

However, it seems that this is not supported by distill. It is also not listed as global knitr option in the documentation on https://rstudio.github.io/distill/,

code from section "code blocks" below:

knitr::opts_chunk$set(
  echo = TRUE,
  warning = TRUE,
  message = TRUE,
  comment = "##",
  R.options = list(width = 60)
)

This website appears to have solved this issue, but I'm not sure if this was done via distill, even though it is listed as example distill-website...

https://www.tidymodels.org/learn/statistics/tidy-analysis/

rkbauer avatar May 08 '21 05:05 rkbauer

  1. Sorry for the confusion- I'll clarify the docs that the tidymodels.org site is a Hugo site. The "color theme" was borrowed to show those same colors in a distill site.

  2. Did you try:

knitr::opts_chunk$set(
  collapse = TRUE,
  ...any additional knitr options you want to override here...
)

I tried this and it worked in a distill blog post, but looks a bit different b/c of the distill code styling.

apreshill avatar May 08 '21 13:05 apreshill

Hi, And thanks for the rapid reply. I tried this but it's unfortunately not working either.. I added this code at the beginning of a markdown post:

knitr::opts_chunk$set(
  collapse = TRUE
)

And this code in my theme.css to highlight entire chunk and to avoid overflow on the right.

d-article pre  {
  background-color: #dae7f1;
}

d-article pre, d-article div.sourceCode, d-article div.sourceCode pre { overflow: auto !important; }

Here is an example. The output is still not condensed.. It seems like that the collapse = TRUE-statements are generally ignored, no matter if I put them in the chunk arguments or in the overall options as you suggested.

plot(avg1, avg2) 
avg1-avg2
abline(0,b = 1,lty="dotted")
cor(avg1,avg2)
mean(avg1-avg2)

image

rkbauer avatar May 09 '21 06:05 rkbauer

Hi,

looking at the codebase of distill and comparing with knitr, I can confirm that collapse chunk option is not supported by distill

In fact, distill_article() will redefine knitr's hooks and this will modify the expected behavior for collapse = TRUE to work. Also when highlight_downlit = TRUE is used which is the default.

This would require some work on distill to see how to support it while keeping the special code folding feature of distill to work, and downlit highlighting.

cderv avatar May 10 '21 13:05 cderv