I'm trying to knit an HTML document from RMarkdown
, and hide the section from both the Table of Contents (ToC) and body of the output (HTML file), while while still knitting (executing) all of the code and contents.
I'm not looking to hide just the code chunk - this can be done through echo = FALSE
.
I tried using the {.hidden}
option meant for flexdashboards but it only partially solves the problem, i.e. the whole section (called # The section I want to hide
in the example below) disappears from the HMTL output itself, but not the table of contents.
Code example:
---
output:
html_document:
df_print: kable
fig_height: 2
fig_width: 2
number_sections: yes
toc: yes
toc_float: yes
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE,
warning = FALSE,
message = FALSE,
cache = FALSE,
dpi = 75,
comment = '')
```
# R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r cars}
summary(cars)
```
# Including Plots
You can also embed plots, for example:
```{r pressure, echo=FALSE}
plot(pressure)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
# The section I want to hide {.hidden}
Super-secret text (section content I don't want to show).
```{r}
sumCars <- summary(cars)
```
# This the section I want to show again
```{r}
sumCars[1,]
```
Output:
How can I hide the document section while still knitting?
include = FALSE
as chunk option. It still gets evaluated. – Capitoline