我正在制作一个包含 RStudio 中的绘图的长 .qmd 脚本,并且我希望有标题供我导航我的脚本,但是这些标题在渲染的文档中不应该可见。如果我将标题放在 {r} 块内,那么它不会显示在 RStudio 脚本右侧的“大纲”中,但如果我将它们放在 {r} 块之外,则标题将显示在渲染的文档,我不想要。
---
title: "Title of my document"
format:
html:
self-contained: true
execute:
echo: false
warning: false
message: false
---
# This heading will be showed in the outline (good) but also in the rendered document (bad) ####
```{r}
# This heading will not be showed in the outline (bad) and not in the rendered document (good) ####
library(dplyr)
...more code
有什么方法可以添加标题,以便通过 RStudio 中 .qmd 文件中的“大纲”功能进行导航,这些标题不会显示在渲染的文档中?
需要明确的是,当我编写普通的 R 脚本 (.R) 时,我会添加标题来进行导航,如下所示:
# 1. Heading ####
some code
## 1.1. Subheading ####
some more code
...将其添加到源窗格的“大纲”部分:
您可以将
{.hidden}
用于您只想在文档大纲中显示的标题,如下所示:
---
title: "Title of my document"
format:
html:
self-contained: true
execute:
echo: false
warning: false
message: false
---
# This heading will be showed in the outline (good) but also in the rendered document (bad) {.hidden}
```{r}
# This heading will not be showed in the outline (bad) and not in the rendered document (good) ####
library(dplyr)
```
输出文件及大纲: