
Export LLM Conceptual Analyses to a UTF-8 Text File
export_conceptual_analysis.RdWrites the formatted conceptual analyses produced by efa_optimizer to a UTF-8 encoded text file.
Internally calls print_conceptual_analysis with width = 100 and show_stats = TRUE, capturing its console output via sink().
After writing, emits a short confirmation via message() and invisibly returns the output file path.
Arguments
- resultado
A result list returned by
efa_optimizer; must contain$conceptual_analysisand$config_used(seeprint_conceptual_analysis).- file
Character path to the output text file (UTF-8). Required (there is no default, so nothing is written to the working directory unless asked); for a throw-away file use, e.g.,
file.path(tempdir(), "conceptual_analysis.txt"). If it exists, it will be overwritten.
Details
What gets written.
The function captures the full console rendering of print_conceptual_analysis (headings, section dividers, emojis, warnings, and technical stats) and writes it to file using UTF-8 encoding.
Because print_conceptual_analysis is bilingual, headings will appear in Spanish when resultado$config_used$ai_config$language is "spanish" (or "español"); otherwise, English is used.
Formatting choices. Text is wrapped at 100 characters per line and per-item technical statistics are always included (primary loading, \(h^2\), RMSEA at removal, and removal reason) when available.
Encoding and Unicode.
Output is forced to UTF-8. Unicode symbols used by print_conceptual_analysis (e.g., a bar chart symbol, a warning sign, a cross mark) will be preserved; ensure your editor is set to UTF-8 to avoid mojibake.
Side effects and limitations.
The function uses sink(file, encoding = "UTF-8") followed by sink() to restore the console.
If an error interrupts execution before the second sink(), the connection may remain diverted; call sink() manually to reset if needed.
Value
Invisibly returns the file path (character scalar). A brief confirmation message is also emitted with message(), of the form “Análisis exportado a: <file>”.
Examples
# Example mock object (see print_conceptual_analysis() examples for structure)
resultado <- list(
conceptual_analysis = list(
removed = list(DP1 = "Desde el punto de vista psicométrico..."),
kept = list(DP2 = "Psychometrically, the item shows..."),
item_stats = list(DP1 = list(loading = 0.22, h2 = 0.11,
rmsea_at_removal = 0.095, reason = "Cross-loading"))
),
config_used = list(
ai_config = list(
language = "spanish",
item_definitions = list(
DP1 = "La gente generalmente piensa que soy inmoral porque soy LGBT.",
DP2 = "Me tratan diferente porque no soy heterosexual."
)
)
)
)
out <- export_conceptual_analysis(resultado,
file = file.path(tempdir(), "conceptual_analysis.txt"))
#> Análisis exportado a: /tmp/RtmpNtsLuD/conceptual_analysis.txt
out # invisible return; prints the path if typed
#> [1] "/tmp/RtmpNtsLuD/conceptual_analysis.txt"
# Read first lines to verify encoding and content:
head(readLines(out, encoding = "UTF-8"))
#> [1] ""
#> [2] "═════════════════════════════════════════════"
#> [3] "ANÁLISIS CONCEPTUAL DE ÍTEMS ELIMINADOS "
#> [4] ""
#> [5] "═════════════════════════════════════════════"
#> [6] ""