gpt4 book ai didi

r - 如何在Rmarkdown中添加目录?

转载 作者:行者123 更新时间:2023-12-03 05:13:29 25 4
gpt4 key购买 nike

我正在使用 RStudio 编写 Markdown 文档,并希望在文档顶部添加目录 (TOC),以便用户可以单击相关部分进行阅读。 rpubs 上有一些相关的例子,但现在我似乎找不到它们。请注意,我不使用 pandoc,而且对 Rmdknitr 还很陌生。有没有办法在不使用 pandoc 的情况下添加目录?如果必须使用 pandoc 那么哪些函数是相关的?

编辑

这是一个小示例页面:

---
title: "Sample Document"
output:
html_document:
toc: true
theme: united
---

Header 1
---------------
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>.

## Header 2
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}
summary(cars)
```

You can also embed plots, for example:

```{r, echo=FALSE}
plot(cars)
```
### Header 3
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.

我尝试在 RStudio v 0.98.864 中运行它,它成功了!但遗憾的是它在 0.98.501 和 0.98.507 上不起作用。我正在 0.98.501 中完成我的论文,更新 RStudio 后,我的一些分析不起作用。所以,我恢复到0.98.501。我现在应该怎么做?我真的想要 TOC,但又不会损害其他分析的输出。

最佳答案

语法是

---
title: "Sample Document"
output:
html_document:
toc: true
theme: united
---

the documentation 。确保它位于文档的开头。还要确保您的文档实际上有标题,否则 R 无法告诉您在目录中想要什么。

关于r - 如何在Rmarkdown中添加目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23957278/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com