Skip to contents

Renders an automated report from a completed event study task in one or more output formats. Uses a bundled RMarkdown template with configurable sections. The narrative is assembled ONCE before the format loop – es_advise is never called per format (NARR-01).

Usage

generate_report(
  task,
  output_file = "event_study_report.html",
  format = "html",
  title = "Event Study Report",
  author = NULL,
  sections = c("exec_summary", "data_methods", "results", "diagnostics", "robustness",
    "references"),
  cross_sectional = NULL,
  confidence_level = 0.95,
  interactive = TRUE,
  advice = NULL,
  narrative = NULL,
  provider = NULL,
  verbose = getOption("eventstudy.verbose", TRUE),
  ...
)

Arguments

task

A fitted EventStudyTask or PanelEventStudyTask.

output_file

Output file path (extension overridden per format). Default "event_study_report.html".

format

Character vector of output formats, any subset of c("html", "pdf", "word", "md"). Default "html". Multiple formats render one file per format sharing a common basename. Missing optional toolchains emit one message() each and are skipped; only inability to render HTML raises stop().

title

Report title string.

author

Author name (optional, default "").

sections

Character vector of sections to include. Default is all six fixed sections: c("exec_summary","data_methods","results","diagnostics","robustness","references").

cross_sectional

Optional cross-sectional regression results to include.

confidence_level

Confidence level for plots. Default 0.95.

interactive

Logical. Use interactive plotly plots in HTML output. Default TRUE.

advice

An optional grounded Advice object returned by es_advise(task_type = "report_writing"). When supplied and valid, renders an AI Advisor Interpretation section. A supplied but invalid advice is silently coerced to NULL with one warning() – the report is never broken.

narrative

An optional named list keyed by section (e.g. list(exec_summary = "...", data_methods = "...", results = "...", robustness = "...")), typically from assemble_report_narrative(). When NULL (default), the render output is byte-identical to the v0.63.x baseline. A supplied but invalid narrative is silently coerced to NULL with one warning().

provider

Optional LLM provider passed to assemble_report_narrative() when narrative is NULL. If both provider and narrative are NULL, a fully offline narrative is assembled. Ignored when a pre-built narrative list is supplied by the caller.

verbose

Logical; if FALSE, suppress informational messages. Default getOption("eventstudy.verbose", TRUE).

...

Additional arguments passed to rmarkdown::render.

Value

A named character vector of output file paths, invisibly, keyed by format name (e.g. c(html = "/tmp/report.html", pdf = "/tmp/report.pdf")). A single-format call returns a length-1 named vector: result[["html"]] and result[[1L]] both resolve (backward-compatible with prior single-path callers).

See also

Examples

# \donttest{
data(dieselgate)
task <- EventStudyTask$new(dieselgate$firm, dieselgate$index, dieselgate$request)
task <- run_event_study(task, ParameterSet$new())

# Single HTML format written to a temporary directory
out  <- file.path(tempdir(), "event_study_report.html")
path <- generate_report(task, output_file = out, format = "html")
#> Report mode: Offline rule-based narrative
#> Report generated: /tmp/RtmpE2WNJT/event_study_report.html
path[["html"]]
#> [1] "/tmp/RtmpE2WNJT/event_study_report.html"
# }