【问题标题】:Generating a table of contents (toc) when using knitr's spin()使用 knitr 的 spin() 时生成目录 (toc)
【发布时间】:2014-09-16 15:17:39
【问题描述】:

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

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

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

【问题讨论】:

  • 如何在旋转脚本中标记标题?我们可以提供一些示例代码吗?

标签: r knitr knitr-spin


【解决方案1】:

给定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。

信用:http://rpubs.com/alobo/spintutorial

【讨论】:

    【解决方案2】:

    或者,您可以在 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  
    #' ---
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-21
      • 1970-01-01
      • 2017-12-26
      • 1970-01-01
      相关资源
      最近更新 更多