繁体   English   中英

使用knitr的spin()时生成目录(toc)

[英]Generating a table of contents (toc) when using knitr's spin()

我使用knitr的spin()函数来生成html报告。

有没有办法让spin()以某种方式为注释中嵌入的标题生成目录(toc)?

(注意:我不能使用pandoc,必须使用knitr提供的markdown和html生成器。)

鉴于spin.R

#' # Heading
x=1:10
y=runif(10)

#' And now we can do this

#' # Fitting

lm(y~x)

然后两步:

spin("spin.R",knit=FALSE)
knit2html("spin.Rmd", options = c("toc", markdown::markdownHTMLOptions(TRUE)))

用toc生成html。

图片来源: http//rpubs.com/alobo/spintutorial

或者,您可以在R脚本的顶部添加YAML标题,然后单击最新版本的RStudio中的“编译笔记本”按钮。 示例YAML是:

#' ---
#' title: "My Analysis "
#' author: "Me"
#' date: "2016-03-11"
#' output:
#'    word_document:
#'       reference_docx: knitr_template.docx
#'       toc: true
#' always_allow_html: yes  
#' ---

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM