save_results: Save Pipeline Results to CSV or xlsx

View source: R/output.R

save_resultsR Documentation

Save Pipeline Results to CSV or xlsx

Description

Writes all standard output files to output_folder:

  • <label>_fit_indices.csv – CFI/TLI/RMSEA/SRMR for all models.

  • <label>_CFA_loadings.csv – standardised loading matrix (wide).

  • <label>_ESEM_loadings.csv – standardised loading matrix (wide).

  • <label>_BESEM_loadings.csv – standardised loading matrix (wide).

  • <label>_loadings_comparison.csv – R vs Mplus loadings, long format with SEs, z-scores, p-values, and diff_std.

  • <label>_omega.csv – Reliability indices (if indices is supplied).

  • <label>_results.xlsx – Single xlsx workbook with all results (when xlsx = TRUE).

Usage

save_results(results, omega = NULL, output_folder, label = NULL, xlsx = FALSE)

Arguments

results

An esem_comparison_pipeline object from run_comparison.

omega

Optional. A reliability_indices object from compute_indices. If supplied, reliability indices are saved.

output_folder

Character. Path to the folder where files are written. Created if it does not exist.

label

Character. Prefix for output file names. Defaults to results$spec$label.

xlsx

Logical. If TRUE, writes a single <label>_results.xlsx file instead of individual CSVs. Requires the openxlsx2 package (install.packages("openxlsx2")). Sheets: Fit_Indices, CFA_Loadings, ESEM_Loadings (if ESEM fit present), BESEM_Loadings (if B-ESEM fit present), Reliability (if omega supplied), Loadings_Comparison (if Mplus results present and both ESEM and B-ESEM fits available). Primary loadings in ESEM/BESEM sheets are bolded; G-column bolded in BESEM sheet. Default FALSE.

Value

Invisibly returns a character vector of file paths written.

Examples

data("HolzingerSwineford1939", package = "lavaan")

spec <- specify_model(
  Visual  = c("x1", "x2", "x3"),
  Textual = c("x4", "x5", "x6"),
  Speed   = c("x7", "x8", "x9"),
  data    = HolzingerSwineford1939,
  label   = "Holzinger-Swineford"
)


results <- run_comparison(spec, n_starts = 5L)
indices <- compute_indices(results)
save_results(results, indices,
             output_folder = file.path(tempdir(), "esem_results"))



bifactory documentation built on Oct. 28, 2026, 1:06 a.m.