Skip to contents

Prepares a named list of mschart objects for insertion into a Word document using officer. Typically used with plots generated by makeme() with crowd parameter and type = "cat_plot_docx".

Usage

crowd_plots_as_officer(plot_list, extract_metadata = TRUE)

Arguments

plot_list

A named list of mschart objects. Names become section labels. Typically created with: makeme(crowd = c("target", "others"), type = "cat_plot_docx", docx_return_object = TRUE).

extract_metadata

Logical. If TRUE (default), extracts and includes metadata (like dep_label_prefix) from each plot object.

Value

A list with class "saros_officer_plots" containing:

  • plots: Named list of mschart objects ready for officer insertion

  • metadata: List of metadata for each plot (if extract_metadata = TRUE), including plot names, dep_label_prefix, and other attributes; NULL if extract_metadata = FALSE

  • n_plots: Integer count of valid mschart objects after filtering

Details

This function validates and structures plot objects for Word document assembly. Unlike crowd_plots_as_tabset() which generates Quarto markdown directly, this function returns a structured R object that can be used programmatically with officer to build Word documents.

Typical Workflow:

  1. Generate mschart objects with makeme(..., type = "cat_plot_docx", docx_return_object = TRUE, crowd = ...)

  2. Pass the list to crowd_plots_as_officer() for validation and structuring

  3. Use the returned object to insert plots into a Word document via officer

Metadata Extraction: When extract_metadata = TRUE, the function extracts:

  • dep_label_prefix: Main question text (from get_dep_label_prefix())

  • name: Plot name from the list

  • Additional attributes attached to the plot object

See also

Examples

if (FALSE) { # \dontrun{
# Generate mschart objects for Word
plots <- makeme(
  data = ex_survey,
  dep = b_1:b_3,
  crowd = c("target", "others"),
  mesos_var = "f_uni",
  mesos_group = "Uni of A",
  type = "cat_plot_docx",
  docx_return_object = TRUE
)

# Prepare for officer assembly
officer_plots <- crowd_plots_as_officer(plots)

# Use in officer workflow
library(officer)
doc <- read_docx()
for (plot_name in names(officer_plots$plots)) {
  doc <- doc |>
    body_add_par(plot_name, style = "heading 2") |>
    body_add_par(officer_plots$metadata[[plot_name]]$dep_label_prefix) |>
    mschart::body_add_chart(officer_plots$plots[[plot_name]])
}
print(doc, target = "output.docx")
} # }