[英]Generating a table of contents (toc) when using knitr's spin()
I use knitr's spin() function to generate html reports. 我使用knitr的spin()函数来生成html报告。
Is there a way to make spin() generate a table of contents (toc) for headings embedded in the comments somehow? 有没有办法让spin()以某种方式为注释中嵌入的标题生成目录(toc)?
(Note: I cannot use pandoc for that and have to use the markdown & html generator provided by knitr.) (注意:我不能使用pandoc,必须使用knitr提供的markdown和html生成器。)
Given spin.R
: 鉴于
spin.R
:
#' # Heading
x=1:10
y=runif(10)
#' And now we can do this
#' # Fitting
lm(y~x)
then two steps: 然后两步:
spin("spin.R",knit=FALSE)
knit2html("spin.Rmd", options = c("toc", markdown::markdownHTMLOptions(TRUE)))
produces html with a toc. 用toc生成html。
Credit: http://rpubs.com/alobo/spintutorial 图片来源: http : //rpubs.com/alobo/spintutorial
Alternatively you can add a YAML header at the top of your R script and then click the Compile Notebook button in the latest versions of RStudio. 或者,您可以在R脚本的顶部添加YAML标题,然后单击最新版本的RStudio中的“编译笔记本”按钮。 Example YAML is:
示例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.