Skip to contents

Two-pass report generation in one call: (1) regenerates abbreviations.tex from standard_footnotes.yaml and renders shell_qmd with Quarto against a quartifyr docx reference-template, (1.5) applies styling_apply_layout() to the rendered shell – a dynamic page header (from header-format: frontmatter) and, if the .qmd uses {{< body-start >}}, splitting front matter from the body into separate OOXML sections so body page numbering restarts at 1 – then (2) hands the resulting shell to reportifyr::build_report() to fill in tables, figures, and footnotes from OUTPUTS/, and (when status = "final") reportifyr::finalize_document() on top of that.

Usage

render_report(
  shell_qmd,
  status = c("draft", "final"),
  reference_doc = NULL,
  style = NULL,
  override = NULL,
  standard_footnotes_yaml = file.path(dirname(shell_qmd), "report",
    "standard_footnotes.yaml"),
  config_yaml = file.path(dirname(shell_qmd), "report", "config.yaml"),
  figures_path = file.path(dirname(shell_qmd), "OUTPUTS", "figures"),
  tables_path = file.path(dirname(shell_qmd), "OUTPUTS", "tables"),
  recalculate_fields = FALSE,
  resolve_same_page_crossrefs = FALSE,
  quarto_timeout = 600,
  quarto_bin = NULL,
  soffice_bin = NULL,
  strict = FALSE,
  offline = NULL,
  fit_tables = TRUE
)

Arguments

shell_qmd

Path to the shell .qmd, at the project's root alongside _extensions/ (standard Quarto project layout – extensions are discovered relative to the qmd being rendered; see install_quartifyr_extension()). The project's _quarto.yml must set project: {output-dir: report/shell} so the rendered docx lands in report/shell/, matching what reportifyr::make_doc_dirs() expects (it derives report/draft//report/final/ output paths by substring-replacing "shell" with "draft"/"final" in the containing directory of the rendered docx – not the source qmd – so this is load-bearing, not just a convention).

status

"draft" or "final". Sets the title page's DRAFT/FINAL stamp (via Quarto's -M document-status:) and, when "final", also runs reportifyr::finalize_document() to produce a report/final/ output alongside the report/draft/ one.

reference_doc

Path to the docx reference-template. NULL (default) checks shell_qmd's own frontmatter and the project's _quarto.yml (via quarto::quarto_inspect(), so this follows Quarto's own frontmatter-over-project merge precedence) for an already-configured format: {docx: {reference-doc: ...}} and, if found, leaves it alone – quarto render picks it up on its own, same as a plain quarto render would. Only when neither sets one does this fall back to the template bundled with this package (inst/templates/org-reference.docx, built from inst/python/styles/default.yaml), with a one-time notice pointing at styling_build_reference_docx() to build a custom one instead. Pass an explicit path here to always use it regardless of any Quarto-level setting.

style, override

Optional style YAML paths – when style is given, its equation.font is applied to the rendered shell's default math font via styling_apply_layout() (see that function; pandoc's docx writer doesn't carry this setting through from reference_doc itself, so it has to be reapplied here, after rendering). Independent of reference_doc – if reference_doc was itself built from a style YAML (styling_build_reference_docx()), pass the same path here to keep the two in sync. NULL (default) leaves the rendered docx's math font untouched.

standard_footnotes_yaml, config_yaml, figures_path, tables_path

Passed through to reportifyr; default to the standard project layout reportifyr::initialize_report_project() creates, alongside shell_qmd.

recalculate_fields

Whether to run styling_recalculate_fields() (headless LibreOffice) on each produced docx afterward, so the delivered file's ToC page numbers/entries are already resolved instead of showing "Right-click to update field". Default FALSE: this step has been observed to hang intermittently in some environments for reasons not yet root-caused (see recalculate_fields.py's docstring) – opt in once you've confirmed it's reliable in your own environment. A failure here only warns, it never fails the overall render (the doc is still fully usable, just needs a manual "select all, F9" in Word). The failure is recorded in the result (status becomes "error", see strict).

resolve_same_page_crossrefs

Whether to run styling_resolve_same_page_crossrefs() (headless LibreOffice, read-only – it never re-saves the docx itself) on each produced docx afterward, to resolve any crossref-hyperlinks: "same-page" markers into a final hyperlinked/not decision now that real content and pagination exist. A no-op (skips LibreOffice entirely) if the .qmd didn't use that setting. Default FALSE, same reasoning as recalculate_fields – it drives the identical headless-LibreOffice mechanism and inherits its intermittent-hang behavior (see same_page_crossrefs.py's docstring). If never enabled, a document using crossref-hyperlinks: "same-page" just stays hyperlinked everywhere – the same safe fallback apply-layout already leaves in place. A failure here only warns, same as recalculate_fields.

quarto_timeout

Seconds to allow the quarto render subprocess before killing it and signalling an error of class quartifyr_quarto_timeout. Default 600; Inf disables the limit. The whole process tree is cleaned up on timeout or interrupt (Quarto spawns Deno, Pandoc and possibly R/knitr children that would otherwise outlive it). Only this step is bounded: quarto inspect, quarto list extensions, the Python styling step and reportifyr's pass 2 have no timeout of their own, so a caller that needs a hard limit on the whole job must enforce it itself.

quarto_bin

Path to the Quarto executable. NULL (default) uses the QUARTO_PATH environment variable if set, else quarto on PATH. When given, it is also exported as QUARTO_PATH for the duration of the call, so the quarto R package's own helpers (quarto_inspect(), quarto_list_extensions()) use the same binary.

soffice_bin

Path to the LibreOffice executable used by recalculate_fields and resolve_same_page_crossrefs. NULL (default) uses the QUARTIFYR_SOFFICE_BIN environment variable if set, else soffice on PATH. When either step is requested the executable is checked before anything is rendered, and the path and soffice --version that ran are recorded in the result's versions$libreoffice.

strict

If TRUE, signal an error of class quartifyr_render_incomplete (carrying the result as $result) when the render finished but the result's status is not "ok": unfilled {rpfy}: placeholders, missing metadata sidecars, or a requested LibreOffice step that failed. Default FALSE, which returns the result either way so existing callers keep working; use TRUE in CI and background jobs where an incomplete document must not look like success. With strict = TRUE the result carried on the condition has status = "error", with the reason added to errors, even if the render itself only warned. Without it, a returned result (and the script's exit status 0) only means the render finished, not that it was complete: check status.

offline

Whether to render without any network access. NULL (default) follows offline mode as set by options(quartifyr.offline = TRUE) or the UV_OFFLINE environment variable (see vignette("offline")). When on, render_report() sets UV_OFFLINE=1, UV_NO_INDEX=1, UV_PYTHON_DOWNLOADS=never and UV_NO_SYNC=1 for the whole call, so quartifyr's styling steps and reportifyr's pass 2 use the already-provisioned Python environment as it is: nothing is synced, recreated or downloaded, and a cold uv cache is fine. The environment must have been provisioned beforehand, by initialize_quartifyr_project() and reportifyr::initialize_report_project(). A uv failure then signals an error of class quartifyr_offline_failure naming the step. FALSE sets nothing. Renders of one project must not run concurrently: they share its .venv and report/ folders.

fit_tables

Whether to run styling_fit_tables() on each produced docx after reportifyr's pass 2 (default TRUE; plain Python, no LibreOffice). It gives the tables reportifyr inserted explicit column widths from the page section they are in (so a table on a {{< landscape >}} page uses the landscape width), with no column narrower than its longest word and the font reduced in steps, to at most a 7 pt minimum, only when needed. A table still too wide at 7 pt is recorded as a warning in the result. FALSE leaves the widths to the word processor (reportifyr's own autofit). A failure only warns and is recorded in the result, like the LibreOffice steps.

Value

An object of class quartifyr_render_result, a list with:

shell, draft, final

Paths to the docx files (final is NULL unless status = "final").

status

"ok", "warning" or "error". "error" means the delivered document is incomplete: placeholders were left unfilled, or a requested LibreOffice step failed. "warning" means it is complete but reportifyr flagged something (e.g. a missing metadata sidecar).

artifacts

Data frame of the files that exist: role, path, sha256, bytes.

unfilled_placeholders

{rpfy}: magic strings still present in the draft/final docx.

missing_metadata

Artifacts the shell references that have no <stem>_<ext>_metadata.json sidecar (from the project files, plus reportifyr's own log for this run).

warnings, errors

Messages behind a non-"ok" status.

log_dir

reportifyr's log directory for the project.

inputs

Data frame (role, path, sha256, bytes) of the files the render read: the shell .qmd, each figure, table and metadata sidecar it references, standard_footnotes.yaml, config.yaml and the reference-doc.

versions

List of the quartifyr, reportifyr, Quarto, quartifyr_styling (Python) and R versions; NULL where one could not be determined.

started_at, finished_at

UTC timestamps (ISO 8601) of the render.

Everything before pass 2 (a failed Quarto render, a timeout, a failed precondition) signals an ordinary error instead. The same fields are available as JSON, with a schema_version field, from the inst/scripts/render.R script (see system.file("schemas", "render-result-v1.schema.json", package = "quartifyr") for the shape). Within a schema version, new optional fields may appear, so consumers should ignore fields they don't know; removing or renaming a field bumps the version.

After a failed render

A render works in report/.staging-<id>/ and only reaches report/shell, report/draft and report/final once it has finished and been accepted (strict = TRUE rejects anything whose status is not "ok"; otherwise a finished render is delivered as it is, with status saying whether it is complete). So the live folders only ever hold delivered renders, whatever Quarto and reportifyr were doing when a render went wrong.

Once the project checks pass and a render starts, the outputs it is about to regenerate (report/shell/<name>.docx, report/draft/<name>-*.docx, report/final/<name>-final.docx and its _docx_metadata.json, and what reportifyr leaves in report/draft/intermediate_files/) are moved to report/.previous/ first, replacing the copy already there, all or nothing. After a render that fails, times out, is rejected by strict or is interrupted:

  • report/shell, report/draft and report/final hold nothing from this render, or from the earlier one;

  • report/.previous/ holds the last delivered outputs, and is not touched by a failed render (a failure followed by another render never pushes the last good outputs out of it);

  • the failed render's own files, partial ones included, are kept in report/.failed/ with a FAILED file giving the reason, until the next failure replaces them. For a strict rejection the error's result points at the files there;

  • a failure in the project checks that run first touches nothing.

If the R process is killed outright (SIGKILL, a closed session), nothing can clean up: the render's files are left in report/.staging-<id>/, the live folders hold nothing from it, and the next render deletes that folder. Add report/.previous/, report/.failed/ and report/.staging-*/ to .gitignore. abbreviations.tex next to the shell .qmd is regenerated regardless, and an output counts as produced only if it was written after the render began. Renders of one project must not run concurrently.

Known upstream gotcha

Pandoc's docx writer wraps every #-heading section in body-level bookmarkStart/bookmarkEnd markers (siblings of <w:p>, not nested in one). reportifyr's own build_report() -> validate_alt_text_magic_strings() assumes the paragraph right after any {rpfy}: magic string is itself a <w:p>, and crashes with an lxml "Undefined namespace prefix" error if a magic string is the very last thing in a section (the "next paragraph" it finds is actually that trailing bookmarkEnd, or the closing <w:sectPr> at the end of the whole document). Put at least one line of real content (a sentence, a footnote lead-in, anything) after the last magic string in each section to avoid this – confirmed via a real end-to-end render.

Examples

if (FALSE) { # \dontrun{
# Requires Quarto, a reportifyr-initialized project, and a provisioned
# quartifyr Python environment (see initialize_quartifyr_project()) --
# not something to run against arbitrary setup/resource usage here.
render_report("path/to/project/report.qmd", status = "draft")
render_report("path/to/project/report.qmd", status = "final")
} # }