【发布时间】:2014-09-16 15:17:39
【问题描述】:
我使用 knitr 的 spin() 函数来生成 html 报告。
有没有办法让 spin() 以某种方式为嵌入在 cmets 中的标题生成目录 (toc)?
(注意:我不能使用 pandoc,必须使用 knitr 提供的 markdown 和 html 生成器。)
【问题讨论】:
-
如何在旋转脚本中标记标题?我们可以提供一些示例代码吗?
标签: r knitr knitr-spin
我使用 knitr 的 spin() 函数来生成 html 报告。
有没有办法让 spin() 以某种方式为嵌入在 cmets 中的标题生成目录 (toc)?
(注意:我不能使用 pandoc,必须使用 knitr 提供的 markdown 和 html 生成器。)
【问题讨论】:
标签: r knitr knitr-spin
给定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)))
生成带有目录的 html。
【讨论】:
或者,您可以在 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
#' ---
【讨论】: