
Split a book section into chapter files using known headings
Source:R/split_book_section_by_headings.R
split_book_section_by_headings.RdSplits one oversized section text file into chapter-level .txt files by
finding the ordered chapter headings supplied from a table of contents. This
is useful when uppercase headings alone are ambiguous because non-chapter
subsections use the same visual style.
Arguments
- input_file
Character scalar. Path to the section
.txtfile.- chapter_titles
Character vector of chapter titles, in the order they appear in
input_file.- output_dir
Character scalar. Folder where chapter files should be written. Defaults to a
chapters/subfolder besideinput_file.- chapter_ids
Optional character vector of file stems to use for output files. Defaults to numbered slugs based on
chapter_titles.- extension
Character scalar output extension, without a leading dot. Defaults to
"txt".- overwrite
Logical scalar. If
TRUE, replace existing output files. Defaults toFALSE.- include_heading
Logical scalar. If
TRUE, keep each chapter heading as the first line of its output file. Defaults toTRUE.- allow_missing
Logical scalar. If
TRUE, missing headings are skipped with a warning. Defaults toFALSE.