
Package Multiple Already-Rendered Reports Into an Indexed Zip
Source:R/zip_reports.R
zip_reports.RdGiven a data frame describing an ordered set of already-rendered Quarto reports grouped into stage folders, copies their existing PDF/DOCX/HTML outputs into a staged build directory, builds an Excel index with hyperlinks to each report, optionally bundles arbitrary data-deliverable files alongside them, and zips the result.
Arguments
- reports
A data frame/tibble with one row per report and columns
name(display name),path(path to the.qmdsource — the corresponding.pdf/.docx/.htmloutput paths are derived by swapping its extension), and optionallystage(subfolder to group the report under;NA/empty becomes"99_Other") anddescription. The stage is used as a folder name inside the zip, so path separators and the characters a file name cannot hold on Windows become-and leading or trailing dots, dashes and spaces are dropped ("../x"gives"x"); ordinary names such as"01 Results"are kept as they are. The index shows the stage as it was given.- output_formats
Character vector of formats to look for and include: any of
"pdf","docx","html", or"all"for all three. Defaults toc("pdf", "docx").- data_deliverables
Character vector of additional file paths to copy into a top-level
data/folder in the zip. Defaults tocharacter(0). A path that does not exist is skipped. Files that share a file name (a/results.csv,b/results.csv) are all kept, the later ones with a numeric suffix (results_2.csv) and a warning. A file that cannot be copied (open in another program, a folder instead of a file) is left out with a warning.- zip_name
Name of the output zip file. Defaults to
all_reports_<date>.zip.- output_dir
Directory the finished zip is written to. Defaults to
getwd().- docx_from_pdf
Optional function
function(src_pdf, dest_docx)used to createdest_docxfrom an existingsrc_pdfwhen a report requests"docx"output but no (or a stale).docxfile exists next to its.qmdsource. A DOCX is stale when it is older than its PDF. IfNULL(default), a missing DOCX is skipped silently and a stale one is skipped with a warning; it is never shipped. The function counts as having failed when it returnsFALSE(asconvert_pdf_to_docxdoes) or when no DOCX at least as new as the PDF is there afterwards; a warning says so and no DOCX is shipped for that report. Any other return value is taken as success. In the index, the DOCX cell of a report whose PDF exists but that has no DOCX to ship reads- docx_strict
Logical. When
TRUE, fails loudly (stops execution with an error) if no PDF-to-DOCX conversion backend is available or if conversion fails to produce a current.docxfor a requested report. WhenFALSE(default), warns and skips missing/stale DOCXs. Passdocx_strict = TRUEexplicitly when packaging deliverables that must strictly guarantee current DOCX files.- docx_backend
Conversion backend passed to
convert_pdf_to_docx:"auto"(default),"python","libreoffice", or"word_com".
Details
Unlike zip_render (which renders and zips a single
document), zip_reports does not render anything itself — it
packages outputs that have already been rendered, e.g. by
render_pipeline (or render_pipeline). Report order and staging is entirely the
caller's decision (for example, the topological sort of a project's own
dependency graph) — pass reports pre-ordered. If multiple reports
share the same source stem (for example analysis1/analysis.qmd and
analysis2/analysis.qmd), staged output names are disambiguated to
prevent overwrites within a stage/format folder.
Examples
if (FALSE) { # \dontrun{
reports <- data.frame(
name = c("Introduction", "Results"),
path = c("analysis/intro.qmd", "analysis/results.qmd"),
stage = c("00_intro", "01_results"),
description = c("Project overview", "Primary analysis results")
)
zip_reports(reports, output_formats = c("pdf", "docx"))
} # }