Skip to contents

Writes one .qmd per ## heading in a markdown outline, scaffolding each chapter with headings and placeholder exercises so you can sketch a course before writing any prose.

Usage

draft_book(
  path = "schedule.md",
  dir = ".",
  duration = 15,
  exercise = your_turn,
  overwrite = FALSE
)

Arguments

path

Path to a markdown outline. Defaults to "schedule.md".

dir

Directory to write chapters into. Created if it doesn't exist.

duration

Minutes allotted to the chapter, shown in the overview.

exercise

A function returning the markdown lines for a section's exercise, or NULL to omit exercises entirely. Defaults to your_turn().

overwrite

Overwrite chapters that already exist? Defaults to FALSE, which skips them and leaves their contents untouched.

Value

Invisibly, the paths written or skipped.

Details

Existing files are skipped unless overwrite = TRUE. Regenerating with overwrite = TRUE discards anything written into those chapters by hand, so reach for it while the structure is still settling, not after.

Examples

schedule <- system.file("extdata", "schedule.md", package = "rithmatist")
book <- withr::local_tempdir()
draft_book(schedule, dir = book)
#> ✔ Created /tmp/Rtmpe7cYU7/file1a7242b4770f.
#> ✔ Wrote /tmp/Rtmpe7cYU7/file1a7242b4770f/project-organisation.qmd.
#> ✔ Wrote /tmp/Rtmpe7cYU7/file1a7242b4770f/code-style-and-readability.qmd.
#> ✔ Wrote /tmp/Rtmpe7cYU7/file1a7242b4770f/writing-readable-code.qmd.
#> ✔ Wrote /tmp/Rtmpe7cYU7/file1a7242b4770f/writing-functions.qmd.
#> ✔ Wrote /tmp/Rtmpe7cYU7/file1a7242b4770f/writing-a-reprex-getting-unstuck.qmd.
#> ✔ Wrote /tmp/Rtmpe7cYU7/file1a7242b4770f/putting-it-all-together.qmd.
list.files(book)
#> [1] "code-style-and-readability.qmd"      
#> [2] "project-organisation.qmd"            
#> [3] "putting-it-all-together.qmd"         
#> [4] "writing-a-reprex-getting-unstuck.qmd"
#> [5] "writing-functions.qmd"               
#> [6] "writing-readable-code.qmd"