lith lith - 1 year ago 99
R Question

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

I use knitr's spin() function to generate html reports.

Is there a way to make spin() generate a table of contents (toc) for headings embedded in the comments somehow?

(Note: I cannot use pandoc for that and have to use the markdown & html generator provided by knitr.)

Answer Source

Given spin.R:

#' # Heading

#' And now we can do this

#' # Fitting


then two steps:

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

produces html with a toc.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download