【发布时间】:2020-04-13 04:58:55
【问题描述】:
我正在尝试从Rmarkdown 编织一个 HTML 文档,并且正在寻找一种方法来隐藏文档的一部分,同时仍然编织(执行)所有它。
我不想只隐藏代码 chunk - 这可以通过 echo = FALSE 来完成。
对flexdashboards 使用{.hidden} 选项只能部分解决问题。
部分会从 HMTL 输出本身中消失,而不是 目录。
代码示例:
---
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,]
```
输出:
如何在编织的同时隐藏文档部分?
【问题讨论】:
-
我并不完全清楚:是要隐藏的代码块之间的文本,还是实际的代码块?或两者?您可以通过使用
include = FALSE作为块选项来简单地隐藏代码块。它仍然会被评估。
标签: r r-markdown knitr