% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/crowd_plots_as_officer.R
\name{crowd_plots_as_officer}
\alias{crowd_plots_as_officer}
\title{Convert List of Plots to officer-Compatible Format}
\usage{
crowd_plots_as_officer(plot_list, extract_metadata = TRUE)
}
\arguments{
\item{plot_list}{A named list of mschart objects. Names become section labels.
Typically created with:
\code{makeme(crowd = c("target", "others"), type = "cat_plot_docx", docx_return_object = TRUE)}.}

\item{extract_metadata}{Logical. If \code{TRUE} (default), extracts and includes
metadata (like \code{dep_label_prefix}) from each plot object.}
}
\value{
A list with class \code{"saros_officer_plots"} containing:
\itemize{
\item \code{plots}: Named list of mschart objects ready for officer insertion
\item \code{metadata}: List of metadata for each plot (if \code{extract_metadata = TRUE}),
including plot names, dep_label_prefix, and other attributes; \code{NULL} if
\code{extract_metadata = FALSE}
\item \code{n_plots}: Integer count of valid mschart objects after filtering
}
}
\description{
Prepares a named list of mschart objects for insertion into a Word document
using officer. Typically used with plots generated by \code{\link[=makeme]{makeme()}} with
\code{crowd} parameter and \code{type = "cat_plot_docx"}.
}
\details{
This function validates and structures plot objects for Word document assembly.
Unlike \code{\link[=crowd_plots_as_tabset]{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.

\strong{Typical Workflow:}
\enumerate{
\item Generate mschart objects with \code{makeme(..., type = "cat_plot_docx", docx_return_object = TRUE, crowd = ...)}
\item Pass the list to \code{crowd_plots_as_officer()} for validation and structuring
\item Use the returned object to insert plots into a Word document via officer
}

\strong{Metadata Extraction:}
When \code{extract_metadata = TRUE}, the function extracts:
\itemize{
\item \code{dep_label_prefix}: Main question text (from \code{\link[=get_dep_label_prefix]{get_dep_label_prefix()}})
\item \code{name}: Plot name from the list
\item Additional attributes attached to the plot object
}
}
\examples{
\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")
}
}
\seealso{
\itemize{
\item \code{\link[=crowd_plots_as_tabset]{crowd_plots_as_tabset()}} for the Quarto/HTML equivalent
\item \code{\link[=makeme]{makeme()}} for creating plots with crowd parameter
\item \code{\link[=get_dep_label_prefix]{get_dep_label_prefix()}} for retrieving main question metadata
\item \code{\link[mschart:body_add_chart]{mschart::body_add_chart()}} for inserting charts into Word documents
}
}
