Word is better than Quarto?

Mail merge is back, baby!

27 February 2025

Backstory 📖

  • NHP outputs reports: need automation/reproducibility
  • Quarto was the answer… until it wasn’t!
  • Solution: meet users where they are (Microsoft Word)
  • Problem: how?

The Word template 📄

A zoomed out view of pages of a complicated-looking Word document with many chunks of text, tables and page orientations. Much of the text is highlighted in green, yellow and blue.

Process ✏️

  1. Record a request with a GitHub issue template.
  2. Tag model-run JSONs on Azure, update site-selections file.
  3. Read SharePoint template with {Microsoft365R}.
  4. Insert content with {officer}.
  5. Write timestamped folder with doc, results, log.
  6. Check output, return to recipient.

Generate a report 🖨️

In R:

populate_template(
  scheme_code = "XYZ",                  # create a report for this scheme
  result_sets = get_nhp_result_sets(),  # fetch results metadata from Azure
  run_stages = list(                    # list the tagged model runs
    primary = "final_report_ndg2",      # main data source for the report
    secondary = "final_report_ndg1"     # used as a comparator
  )
)

Output file structure:

YYYY-MM-DD-HHMMSS_scheme/
 ├──YYYY-MM-DD-HHMMSS_scheme.log                        # log of printed metadata
 ├──YYYY-MM-DD-HHMMSS_scheme_outputs-report_draft.docx  # populated report
 ├──figures/                                            # standalone PNG files
 └──values/                                             # CSVs of calculated values
    

Insert content with {officer} 👮

For calculated values:

  1. Add doc-property fields, e.g. { DOCPROPERTY item_01 }.
  2. Add values to custom doc properties.
  3. Update fields with corresponding property values.

For generated figures:

  1. Add unique target strings, e.g. ‘[Insert Figure 8.2]’.
  2. Find/replace with corresponding PNG.

‘Doing it right’ 💯

  • Github: ‘learn by doing’, challenge and improve things
  • Documentation/version history have saved us!
  • The repo is a springboard for parallel/future work

Reflections 🪞

  • Challenge your thinking, be adaptable to user needs
  • Embrace agility and acknowledge fragility
  • ‘The power of friendship’ keeps things working