Skip to contents

CI jobs, scripts and workspace launchers that run a report build in the background need three things from quartifyr: a way to find out what is wrong before a long build starts, a bound on how long the build can take, and an unambiguous outcome when it finishes. A render that left placeholders unfilled must not look like a success.

Check the project first

check_report_project() never renders. It reads the project’s files and returns a data frame of findings, so a launcher can show problems before queueing a job:

findings <- quartifyr::check_report_project("report.qmd")
findings
#> ── 1 error, 0 warnings
#> ✖ [missing-sidecar] {rpfy}:conc-time.png (line 191) has no metadata sidecar at ...

if (any(findings$severity == "error")) stop("fix the errors above before rendering")

Each row has a check identifier, a severity ("error" or "warning"), the path concerned and a message. It covers:

  • the preconditions render_report() itself enforces (the shell .qmd, the output-dir: report/shell setting, the reportifyr *_init.json marker, the reference-doc and standard_footnotes.yaml);
  • the required Quarto extensions, by scanning _extensions/ rather than asking the Quarto CLI;
  • every {rpfy}: placeholder in the .qmd, plus synopsis: image: entries: the artifact exists under OUTPUTS/figures or OUTPUTS/tables, its <stem>_<ext>_metadata.json sidecar exists and parses, and the abbreviations and meta_type it references are defined in standard_footnotes.yaml;
  • placeholders that are the last thing in their section, which crashes reportifyr’s build_report().

Placeholders inside HTML comments or fenced code blocks are ignored, and files pulled in with {{< include >}} are not scanned.

render_report() shares the precondition checks with this function, so the two cannot disagree. It does not stop on missing artifacts: those are reported in its result instead (below).

Bound the render

render_report() runs quarto render with a timeout and kills the whole process tree (Deno, Pandoc, knitr) when it expires or the R session is interrupted:

quartifyr::render_report("report.qmd", quarto_timeout = 300)

The default is 600 seconds and Inf disables the limit. A timeout signals an error of class quartifyr_quarto_timeout whose message includes the tail of Quarto’s stderr. To use an app-local Quarto instead of the one on PATH, pass quarto_bin = "/path/to/quarto" or set QUARTO_PATH.

The two LibreOffice steps (recalculate_fields, resolve_same_page_crossrefs) find soffice the same way: soffice_bin = "/path/to/soffice" (--soffice-bin), else QUARTIFYR_SOFFICE_BIN, else PATH. When either step is requested the executable is checked before anything is rendered, and the resolved path and its soffice --version line are recorded in the result’s versions$libreoffice.

What is on disk after a failure

A render that fails, times out or is killed must not leave a complete-looking document where a caller would take it for the new one. A render therefore works in report/.staging-<id>/ and only moves into report/shell, report/draft and report/final once it has finished and been accepted: with strict, anything whose status is not "ok" is rejected; without it, a finished render is delivered as it is and status says whether it is complete.

Once the project checks pass and the render starts, render_report() first moves 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 the -clean/-tabs/-tabsfigs files reportifyr keeps in report/draft/intermediate_files/) to report/.previous/, replacing the copy already there, all or nothing. After a failure, a strict rejection or an interruption:

  • report/shell, report/draft and report/final hold nothing from this render, or from an earlier one;
  • the last good outputs are in report/.previous/{shell,draft,final}/, and a failed render never replaces them (so a failure followed by another run doesn’t lose them);
  • the failed render’s own files, partial ones included, are in report/.failed/ with a FAILED file giving the reason, until the next failure replaces them. A strict rejection’s JSON result points at those files, so a caller can inspect what was rejected;
  • otherwise the JSON error object has no artifacts, draft or final;
  • a failure in the project checks that run first (a missing reference-doc, for example) touches nothing, because no render started.

If R is killed outright (SIGKILL, a closed session), nothing can clean up. The render’s files stay in report/.staging-<id>/, nothing from it is in the live folders, and the next render deletes that folder. Add report/.previous/, report/.failed/ and report/.staging-*/ to .gitignore, and don’t run two renders of one project at once.

An output also counts as produced only if it was written after the render began, so a file that predates it is reported as not produced. abbreviations.tex next to the shell .qmd is regenerated on every render, success or not.

Without network access

offline = TRUE (or --offline on the script, or options(quartifyr.offline = TRUE), or UV_OFFLINE=1) makes a render use the project’s Python environment as it is: nothing is synced, recreated or downloaded, so it works from a cold uv cache. The project must have been initialised beforehand. See vignette("offline") for the variables it sets and the exact conditions.

Read the outcome

render_report() returns the three docx paths it always did (shell, draft, final) plus:

Field Meaning
status "ok", "warning" or "error"
artifacts role, path, sha256 and bytes for each file produced
unfilled_placeholders {rpfy}: strings still unresolved in the draft or final docx
missing_metadata artifacts the shell references that have no metadata sidecar
warnings, errors the messages behind a non-"ok" status
log_dir reportifyr’s log directory for the project
inputs role, path, sha256 and bytes for what the render read, hashed before it started: the shell .qmd, _quarto.yml, each figure, table and metadata sidecar it uses, standard_footnotes.yaml, config.yaml, the reference-doc, an explicit style/override YAML, and one row per Quarto extension under _extensions/ (hashed over its files)
versions quartifyr, reportifyr, Quarto, the quartifyr_styling Python package, R and, when a LibreOffice step ran, LibreOffice (NULL where unknown). Also present on the JSON for a render that stopped early, where it could be determined
started_at, finished_at UTC ISO 8601 timestamps

status describes whether the delivered document is complete. "error" means placeholders were left unfilled, or a LibreOffice step you asked for (recalculate_fields, resolve_same_page_crossrefs) failed. "warning" means the document is complete but reportifyr flagged something.

Pass strict = TRUE to turn any non-"ok" status into an error of class quartifyr_render_incomplete. The condition carries the full result as $result:

result <- tryCatch(
  quartifyr::render_report("report.qmd", strict = TRUE),
  quartifyr_render_incomplete = function(e) {
    print(e$result$unfilled_placeholders)
    stop(e)
  }
)

The default is strict = FALSE, so existing callers keep receiving a value. A returned result, and the script’s exit status 0 without --strict, only mean that the render finished: always read status. With strict = TRUE the result on the condition has status = "error" (the reason is added to errors), even if the render itself only warned.

With reportifyr’s default settings, a missing metadata sidecar makes build_report() itself fail rather than leaving a placeholder behind. In that case render_report() signals an error of class quartifyr_pass2_failed that names the missing sidecars.

The script

inst/scripts/render.R wraps the same call for a shell or a launcher. Run it with the project as the working directory, so the project’s renv library is the one that activates:

cd path/to/project
Rscript "$(Rscript -e 'cat(system.file("scripts", "render.R", package = "quartifyr"))')" \
  --project . --shell report.qmd --status draft --json --strict

The JSON result goes to stdout and nothing else does; progress and errors go to stderr. The exit status is 0 only when the render finished (and, with --strict, its status is "ok"; without it, exit 0 does not mean the document is complete). Any error, including a Quarto failure or timeout, prints a JSON object with status: "error", an errors array and an error_class, and exits 1. Bad usage exits 2. Run it with --help for the remaining options (--quarto-timeout, --quarto-bin, --soffice-bin, --reference-doc, --recalculate-fields, …).

A successful result looks like this:

{
  "status": "ok",
  "shell": "/work/project/report/shell/report.docx",
  "draft": "/work/project/report/draft/report-draft.docx",
  "final": null,
  "artifacts": [
    {"role": "shell", "path": "/work/project/report/shell/report.docx", "sha256": "9c8a...", "bytes": 44379},
    {"role": "draft", "path": "/work/project/report/draft/report-draft.docx", "sha256": "fa9e...", "bytes": 341570}
  ],
  "warnings": [],
  "errors": [],
  "unfilled_placeholders": [],
  "missing_metadata": [],
  "log_dir": "/work/project/.rpfy-logs"
}

Versioning

Every result, including the error object a failed render prints, carries schema_version (currently 1). The shape is documented as a JSON Schema in system.file("schemas", "render-result-v1.schema.json", package = "quartifyr"). Within a version, new optional fields can appear, so ignore fields you don’t know. Removing or renaming a field, or changing its meaning, publishes render-result-v2.schema.json and bumps schema_version.

Preflight from a script

inst/scripts/check.R is the same check as check_report_project() for a shell or a launcher, with the same working-directory requirement as render.R:

cd path/to/project
Rscript "$(Rscript -e 'cat(system.file("scripts", "check.R", package = "quartifyr"))')" \
  --project . --shell report.qmd --json

With --json it prints {"schema_version": 1, "findings": [{"check", "severity", "path", "message"}]} on stdout (shape in check-result-v1.schema.json); without it, one line per finding. The exit status is 0 when there are no error findings (warnings are fine), 1 when there is at least one, and 2 for bad usage.

What is not time-limited

quarto_timeout bounds quarto render only. 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 has to enforce it itself (for example with timeout around the script, or the job runner’s own limit). The process-tree cleanup on timeout is tested on Linux and macOS only: the test uses a POSIX stub and pgrep, and Windows cleans up the tree through a different mechanism that is not exercised in CI.

Relative paths

--shell is relative to --project, and render_report() resolves its own path arguments against the calling directory before it changes into the project, so a relative shell_qmd works from any working directory. The renv library that activates is still the one of the directory Rscript started in.

In GitHub Actions

The composite action takes a strict input (default 'false') and exposes the result’s status as a status output:

- uses: jprybylski/quartifyr@v1
  id: render
  with:
    shell-qmd: report.qmd
    strict: 'true'