r_toc_for_Rmd: Automatically creates a table of contents for a .Rmd file...

View source: R/Rmarkdown_utiilities.R

r_toc_for_RmdR Documentation

Automatically creates a table of contents for a .Rmd file string

Description

Scans . Rmd file string for headings (#) and creates a table of contents (hyper linked). The returned string can directly be written as .Rmd file. All code section will be excluded for the (#) search.

Usage

r_toc_for_Rmd(
  c_Rmd,
  toc_heading_string = "Table of Contents",
  create_nb = TRUE,
  create_top_link = TRUE,
  nb_front = TRUE,
  set_first_heading_level = FALSE,
  pagebreak_level = "non"
)

Arguments

c_Rmd

Rmd file string

toc_heading_string

title string for TOC, e.g "Inhaltsverzeichnis", default is "Table of contents".

create_nb

boolean to enable numbering for each heading.

create_top_link

boolean to create link below each heading to jump back to the table of contents.

nb_front

boolean to have the numbering in front of each heading.

set_first_heading_level

set first found heading level to heading 1

pagebreak_level

Automatically add page breaks before new heading. Set the level to insert page breaks to e.g. c("non","1","2","3","4","5","6")

Details

The function argument is a string of a R markdown .Rmd file which can be read via readLines("fileName.Rmd").

Value

.Rmd file string

Examples

print(tbl_of_contents.Rmd)
c_rmd <- r_toc_for_Rmd(tbl_of_contents.Rmd, create_nb = FALSE)
c_rmd
c_rmd <- r_toc_for_Rmd(tbl_of_contents.Rmd,
                        toc_heading_string = "Inhaltsverzeichnis", create_nb = TRUE)
c_rmd

wagnius-GmbH/slvwagner documentation built on Jan. 19, 2025, 7:10 a.m.