
Render a quartifyr report shell (Quarto pass 1) and fill it via reportifyr (pass 2)
Source:R/render-report.R
render_report.RdTwo-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; seeinstall_quartifyr_extension()). The project's_quarto.ymlmust setproject: {output-dir: report/shell}so the rendered docx lands inreport/shell/, matching whatreportifyr::make_doc_dirs()expects (it derivesreport/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 runsreportifyr::finalize_document()to produce areport/final/output alongside thereport/draft/one.- reference_doc
Path to the docx reference-template.
NULL(default) checksshell_qmd's own frontmatter and the project's_quarto.yml(viaquarto::quarto_inspect(), so this follows Quarto's own frontmatter-over-project merge precedence) for an already-configuredformat: {docx: {reference-doc: ...}}and, if found, leaves it alone –quarto renderpicks it up on its own, same as a plainquarto renderwould. Only when neither sets one does this fall back to the template bundled with this package (inst/templates/org-reference.docx, built frominst/python/styles/default.yaml), with a one-time notice pointing atstyling_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
styleis given, itsequation.fontis applied to the rendered shell's default math font viastyling_apply_layout()(see that function; pandoc's docx writer doesn't carry this setting through fromreference_docitself, so it has to be reapplied here, after rendering). Independent ofreference_doc– ifreference_docwas 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, alongsideshell_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". DefaultFALSE: this step has been observed to hang intermittently in some environments for reasons not yet root-caused (seerecalculate_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 (statusbecomes"error", seestrict).- 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 anycrossref-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.qmddidn't use that setting. DefaultFALSE, same reasoning asrecalculate_fields– it drives the identical headless-LibreOffice mechanism and inherits its intermittent-hang behavior (seesame_page_crossrefs.py's docstring). If never enabled, a document usingcrossref-hyperlinks: "same-page"just stays hyperlinked everywhere – the same safe fallbackapply-layoutalready leaves in place. A failure here only warns, same asrecalculate_fields.- quarto_timeout
Seconds to allow the
quarto rendersubprocess before killing it and signalling an error of classquartifyr_quarto_timeout. Default600;Infdisables 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 theQUARTO_PATHenvironment variable if set, elsequartoonPATH. When given, it is also exported asQUARTO_PATHfor the duration of the call, so thequartoR package's own helpers (quarto_inspect(),quarto_list_extensions()) use the same binary.- soffice_bin
Path to the LibreOffice executable used by
recalculate_fieldsandresolve_same_page_crossrefs.NULL(default) uses theQUARTIFYR_SOFFICE_BINenvironment variable if set, elsesofficeonPATH. When either step is requested the executable is checked before anything is rendered, and the path andsoffice --versionthat ran are recorded in the result'sversions$libreoffice.- strict
If
TRUE, signal an error of classquartifyr_render_incomplete(carrying the result as$result) when the render finished but the result'sstatusis not"ok": unfilled{rpfy}:placeholders, missing metadata sidecars, or a requested LibreOffice step that failed. DefaultFALSE, which returns the result either way so existing callers keep working; useTRUEin CI and background jobs where an incomplete document must not look like success. Withstrict = TRUEthe result carried on the condition hasstatus = "error", with the reason added toerrors, 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: checkstatus.- offline
Whether to render without any network access.
NULL(default) follows offline mode as set byoptions(quartifyr.offline = TRUE)or theUV_OFFLINEenvironment variable (seevignette("offline")). When on,render_report()setsUV_OFFLINE=1,UV_NO_INDEX=1,UV_PYTHON_DOWNLOADS=neverandUV_NO_SYNC=1for 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, byinitialize_quartifyr_project()andreportifyr::initialize_report_project(). A uv failure then signals an error of classquartifyr_offline_failurenaming the step.FALSEsets nothing. Renders of one project must not run concurrently: they share its.venvandreport/folders.- fit_tables
Whether to run
styling_fit_tables()on each produced docx after reportifyr's pass 2 (defaultTRUE; 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.FALSEleaves 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,finalPaths to the docx files (
finalisNULLunlessstatus = "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).artifactsData frame of the files that exist:
role,path,sha256,bytes.unfilled_placeholders{rpfy}:magic strings still present in the draft/final docx.missing_metadataArtifacts the shell references that have no
<stem>_<ext>_metadata.jsonsidecar (from the project files, plus reportifyr's own log for this run).warnings,errorsMessages behind a non-
"ok"status.log_dirreportifyr's log directory for the project.
inputsData 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.yamland the reference-doc.versionsList of the quartifyr, reportifyr, Quarto,
quartifyr_styling(Python) and R versions;NULLwhere one could not be determined.started_at,finished_atUTC 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/draftandreport/finalhold 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 aFAILEDfile giving the reason, until the next failure replaces them. For astrictrejection the error'sresultpoints 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")
} # }