make_demographic_table_to_output: Create and Export Demographic Summary Table

View source: R/make_demographic_table_to_output.R

make_demographic_table_to_outputR Documentation

Create and Export Demographic Summary Table

Description

Generates a demographic summary table using 'make_demographic_table()' and exports the resulting table to Word, Excel, or CSV format.

This is a convenience wrapper that combines analysis and output in a single step for users who want immediate file export.

Usage

make_demographic_table_to_output(
  data,
  vars,
  continuous_vars = NULL,
  file_name = "demographic_table",
  format = c("word", "excel", "csv"),
  path = NULL
)

Arguments

data

A data frame containing the dataset.

vars

Character vector of variable names to include in the demographic summary.

continuous_vars

Optional character vector specifying which variables should be treated as continuous. If 'NULL', numeric variables are automatically detected.

file_name

Name of the output file WITHOUT extension (e.g., "demographics").

format

Output format. Must be one of:

  • '"word"' - exports to a Word document (.docx)

  • '"excel"' - exports to an Excel file (.xlsx)

  • '"csv"' - exports to a CSV file (.csv)

path

Optional character string specifying the directory where the file should be saved. If 'NULL' (default), the file is written to a temporary directory. Provide a full directory path or use getwd() during the function call.

Details

The demographic table includes:

  • Categorical variables reported as n (

  • Continuous variables reported as Mean (SD)

Word export uses 'flextable' and 'officer' for formatting. Excel export uses 'openxlsx'. CSV export uses base R 'write.csv()'.

Value

Invisibly returns the full file path to the generated output file.


scaledescr documentation built on April 11, 2026, 5:07 p.m.