Audit the script-figure-slide dependency chain for a chapter
audit_chapter.RdPerforms a comprehensive audit of a lecture chapter:
Discovers scripts in
rsrc/, figures infigure/, and slide.texfilesParses slides to find which figures they reference
Optionally runs all scripts and tracks which figures they produce
Cross-references to identify orphaned figures, orphaned scripts, and missing figures
Arguments
- chapter
Character. Chapter directory name, e.g.
"evaluation".- lecture_dir
Character. Path to the lecture directory. Defaults to
here::here(), i.e. the project root.- lecture
Character. Lecture name for display purposes. Defaults to
basename(lecture_dir).- pattern
Regex pattern to filter scripts. Default
"[.]R$".- timeout
Numeric. Per-script timeout in seconds. Default 300.
- run
Logical. If
TRUE(default), execute scripts. IfFALSE, only perform static analysis (figure existence + slide references).- method
Character. How to detect which figures slides reference:
"auto"(default): Use.flsfiles if they exist for all slides, otherwise fall back to regex. Best for use aftermake slides."regex": Parse.texsource with regex. Fast but can miss dynamically constructed paths (e.g.\\foreachloops)."fls": Parse.flsrecorder files fromlatexmk. More robust but requires prior compilation (make slides). Errors if.flsfiles are missing.
Value
Invisibly: A list with components:
scripts: data.frame of scripts. Includessuccess,error_message,elapsed, andfigures_producedcolumns whenrun = TRUE(NAotherwise).figures: data.frame of figure files on disk (fromfigure/)figures_man: data.frame of manually created figure files (fromfigure_man/)slide_refs: named list mapping slide filenames to theirfigure/referencesslide_refs_man: named list mapping slide filenames to theirfigure_man/referencesorphaned_figures: character vector offigure/filenames (with extension) not used by any slide (excludesattic/subdirectory)orphaned_figures_man: character vector offigure_man/filenames (with extension) not used by any slide (excludesattic/subdirectory)attic_figures: character vector of filenames infigure/attic/attic_figures_man: character vector of filenames infigure_man/attic/orphaned_scripts: character vector of script filenames that succeeded but produced no figure used by any slide (NULLifrun = FALSE)failed_scripts: character vector of script filenames that errored during execution (NULLifrun = FALSE)no_figure_scripts: character vector of script filenames that succeeded but produced no figures (NULLifrun = FALSE)missing_figures: data.frame with columnsfigureandslideforfigure/files referenced by slides but not on diskmissing_figures_man: data.frame with columnsfigureandslideforfigure_man/files referenced by slides but not on diskmissing_pkgs: character vector of R packages required by scripts but not currently installed
Examples
if (FALSE) { # fs::dir_exists(here::here("lecture_i2ml"))
# Static audit only (no script execution)
result <- audit_chapter("evaluation",
lecture_dir = here::here("lecture_i2ml"),
run = FALSE
)
result$orphaned_figures
result$missing_figures
if (FALSE) { # \dontrun{
# Full audit with script execution
result <- audit_chapter("evaluation",
lecture_dir = here::here("lecture_i2ml")
)
} # }
}