Skip to contents

Reads sus_meta processing history to identify which climasus4r pipeline functions were applied, then produces a section-by-section quality assessment covering completeness, demographic distributions, date validity, ICD-10 codes, geographic coverage, and derived variables. Returns an overall quality score (0-100) and supports four output formats.

Usage

sus_data_quality_report(
  df,
  output_format = "console",
  output_file = NULL,
  save_file = TRUE,
  open_file = TRUE,
  check_icd = TRUE,
  check_dates = TRUE,
  top_n = 10,
  lang = "pt",
  verbose = TRUE
)

Arguments

df

A climasus_df or plain data.frame. Arrow objects are materialised automatically.

output_format

Character. One of "console" (default), "gt", "markdown", or "html". The "gt" format returns a gt_tbl object suitable for Quarto / R Markdown documents.

output_file

Character. File path for "markdown" and "html" formats. Defaults to a timestamped filename in the working directory.

save_file

Logical. For "markdown" and "html" formats, whether to write the report to disk. Default TRUE. Set to FALSE to only compute and return the metrics (e.g. $score) without creating a file.

open_file

Logical. When output_format = "html" and save_file = TRUE, automatically open the saved report in the system's default browser (via utils::browseURL()). Default TRUE. Only triggers in interactive sessions.

check_icd

Logical. Include ICD-10 quality section. Default TRUE.

check_dates

Logical. Include date validation section. Default TRUE.

top_n

Integer. Rows shown in frequency tables. Default 10.

lang

Character. Output language: "pt" (default), "en", "es".

verbose

Logical. Print progress messages. Default TRUE.

Value

Invisibly returns a named list of quality metrics (always available regardless of output_format):

$meta

Pipeline metadata from sus_meta

$pipeline

Functions detected in processing history

$overview

Row/column counts, duplicates, column types

$missing

Per-column missing values with quality flags

$demographics

Frequency tables for sex, race, age, education

$dates

Date range and validity per date column

$icd

ICD-10 frequency and validity

$geographic

Municipality and state coverage

$derived

Presence of expected derived variables

$score

Overall quality score 0-100

Examples

if (FALSE) { # \dontrun{
# Console report (default)
sus_data_quality_report(df, lang = "pt")

# gt table (for Quarto / R Markdown)
sus_data_quality_report(df, output_format = "gt", lang = "en")

# Save complete Markdown report
sus_data_quality_report(df, output_format = "markdown",
                        output_file = "reports/quality.md", lang = "pt")

# Save HTML report
sus_data_quality_report(df, output_format = "html",
                        output_file = "reports/quality.html")
} # }