Skip to contents

Turns the nested output of read_stat_tables() into a tidy long table: one row per (analysis, table, result-row, statistic) cell, carrying the STATO typing. This is the form stored in the scienceverse SQLite database, and the basis for later matching of extracted results against the manuscript.

Usage

stat_results_long(
  tables,
  paper_id = NA_character_,
  source_file = NA_character_
)

Arguments

tables

the list returned by read_stat_tables() or read_r_output()

paper_id

optional paper id / DOI to stamp on every row

source_file

optional name of the file the tables were extracted from (e.g. the .jasp/.omv basename, or the script name for run-R output), recorded on every row as provenance for downstream matching, and as the result_id prefix (see below)

Value

a data.frame with columns paper_id, source_file, result_id, analysis, table_title, row_label, statistic, stato_label, stato_iri, and value. result_id identifies ONE CELL — one statistic of one code row — sanitised to lower-case letters/digits/underscores: <source_file>_l<line>_<line_seq>_r<row>_<statistic> for an executed R script (from read_r_output()'s echo-based line attribution), or <source_file>_t<table_index>_r<row>_<statistic> for a JASP/jamovi extraction (no source line exists there, so the table's ordinal position in the rendered document stands in for one); row is the 1-based position of this result within its table, and statistic is that cell's own column header, sanitised the same way and disambiguated with a trailing counter on the rare repeat within one row (a coefficients matrix with a duplicated header). Every ROW's shared prefix (everything before the trailing _<statistic>) is .stat_test_id()'s locator, so cells from the same row share that prefix — only the final segment tells them apart. Empty frame (same columns) when there is nothing to flatten.

Examples

out <- utils::capture.output(t.test(extra ~ group, data = sleep))
long <- stat_results_long(read_r_output(out))
long[, c("statistic", "stato_label", "value")]
#>         statistic                  stato_label   value
#> 1 mean in group 1                  sample mean    0.75
#> 2 mean in group 2                  sample mean    2.33
#> 3               t                  t-statistic -1.8608
#> 4              df number of degrees of freedom  17.776
#> 5         p-value                      p-value 0.07939