This function processes an R Markdown tutorial file to standardize code chunk labels based on section names and exercise numbers. It also renumbers exercises sequentially within each section.
Details
The function applies the following formatting rules:
Exercises are renumbered sequentially within each section
Code chunks are relabeled according to the pattern: section-name-exercise-number
Chunks with
eval = FALSE
receive a-hint-N
suffixChunks with
include = FALSE
receive a-test
suffixChunks with label "setup" are not modified
Chunks with the "file" option are not modified
Unlabeled chunks without key options are not modified
All formatted chunks preserve their original options
Content between quadruple backticks (
Examples
if (FALSE) { # \dontrun{
# Format a tutorial file
new_content <- format_tutorial("path/to/tutorial.Rmd")
# Write the formatted content to a file
writeLines(new_content, "path/to/formatted_tutorial.Rmd")
} # }