From 69b31e124aff05df3492e6e6412c03c64e4e9d12 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 12 Aug 2022 12:59:02 -0700 Subject: [PATCH] CTABLES split file --- src/language/stats/ctables.c | 18 +++-- tests/language/stats/ctables.at | 117 +++++++++++++++++++++++++++++++- 2 files changed, 126 insertions(+), 9 deletions(-) diff --git a/src/language/stats/ctables.c b/src/language/stats/ctables.c index 2611bfebb3..fd296a0021 100644 --- a/src/language/stats/ctables.c +++ b/src/language/stats/ctables.c @@ -5513,23 +5513,27 @@ ctables_execute (struct dataset *ds, struct casereader *input, } struct dictionary *dict = dataset_dict (ds); + + bool splitting = dict_get_split_type (dict) == SPLIT_SEPARATE; struct casegrouper *grouper - = (dict_get_split_type (dict) == SPLIT_SEPARATE + = (splitting ? casegrouper_create_splits (input, dict) : casegrouper_create_vars (input, NULL, 0)); struct casereader *group; while (casegrouper_get_next_group (grouper, &group)) { - /* Output SPLIT FILE variables. */ - struct ccase *c = casereader_peek (group, 0); - if (c != NULL) + if (splitting) { - output_split_file_values (ds, c); - case_unref (c); + struct ccase *c = casereader_peek (group, 0); + if (c != NULL) + { + output_split_file_values (ds, c); + case_unref (c); + } } bool warn_on_invalid = true; - for (c = casereader_read (group); c; + for (struct ccase *c = casereader_read (group); c; case_unref (c), c = casereader_read (group)) { double d_weight = dict_get_case_weight (dict, c, &warn_on_invalid); diff --git a/tests/language/stats/ctables.at b/tests/language/stats/ctables.at index 12caa73d3b..4bdd1744ff 100644 --- a/tests/language/stats/ctables.at +++ b/tests/language/stats/ctables.at @@ -10,7 +10,6 @@ dnl * )CILEVEL in summary label specification dnl - Summary functions: dnl * U-prefix for unweighted summaries. dnl * areaPCT.SUM and UareaPCT.SUM functions. -dnl - SPLIT FILE with SEPARATE splits dnl - Definition of columns/rows when labels are rotated from one axis to another. dnl dnl Not for v1: @@ -3255,7 +3254,6 @@ AT_CHECK([pspp ctables.sps -O box=unicode -O width=120], [0], [dnl ]) AT_CLEANUP - AT_SETUP([CTABLES scale summary functions]) AT_CHECK([ln $top_srcdir/examples/nhtsa.sav . || cp $top_srcdir/examples/nhtsa.sav .]) AT_DATA([ctables.sps], @@ -3535,3 +3533,118 @@ AT_CHECK([pspp ctables.sps -O box=unicode], [0], [dnl ]) AT_CLEANUP +AT_SETUP([CTABLES with SPLIT FILE]) +AT_CHECK([ln $top_srcdir/examples/nhtsa.sav . || cp $top_srcdir/examples/nhtsa.sav .]) +AT_DATA([ctables.sps], +[[GET 'nhtsa.sav'. + +SORT CASES BY qns3a. + +CTABLES /TABLE qn105ba. + +* Layered split has no effect on output. +SPLIT FILE BY qns3a. +CTABLES /TABLE qn105ba. + +* Add column variable qns3a to compare against separate splits. +CTABLES /TABLE qn105ba BY qns3a. + +* Separate splits are truly output separately. +SPLIT FILE SEPARATE BY qns3a. +CTABLES /TABLE qn105ba. +]]) +AT_CHECK([pspp ctables.sps -O box=unicode -O width=80], [0], [dnl + Custom Tables +╭────────────────────────────────────────────────────────────────────────┬─────╮ +│ │Count│ +├────────────────────────────────────────────────────────────────────────┼─────┤ +│105b. How likely is it that drivers who have had too much Almost │ 700│ +│to drink to drive safely will A. Get stopped by the police? certain │ │ +│ Very likely │ 1502│ +│ Somewhat │ 2763│ +│ likely │ │ +│ Somewhat │ 1307│ +│ unlikely │ │ +│ Very │ 609│ +│ unlikely │ │ +╰────────────────────────────────────────────────────────────────────────┴─────╯ + + Custom Tables +╭────────────────────────────────────────────────────────────────────────┬─────╮ +│ │Count│ +├────────────────────────────────────────────────────────────────────────┼─────┤ +│105b. How likely is it that drivers who have had too much Almost │ 700│ +│to drink to drive safely will A. Get stopped by the police? certain │ │ +│ Very likely │ 1502│ +│ Somewhat │ 2763│ +│ likely │ │ +│ Somewhat │ 1307│ +│ unlikely │ │ +│ Very │ 609│ +│ unlikely │ │ +╰────────────────────────────────────────────────────────────────────────┴─────╯ + + Custom Tables +╭─────────────────────────────────────────────────────────────────┬────────────╮ +│ │S3a. GENDER:│ +│ ├─────┬──────┤ +│ │ Male│Female│ +│ ├─────┼──────┤ +│ │Count│ Count│ +├─────────────────────────────────────────────────────────────────┼─────┼──────┤ +│105b. How likely is it that drivers who have had too Almost │ 297│ 403│ +│much to drink to drive safely will A. Get stopped by certain │ │ │ +│the police? Very likely │ 660│ 842│ +│ Somewhat │ 1174│ 1589│ +│ likely │ │ │ +│ Somewhat │ 640│ 667│ +│ unlikely │ │ │ +│ Very │ 311│ 298│ +│ unlikely │ │ │ +╰─────────────────────────────────────────────────────────────────┴─────┴──────╯ + + Split Values +╭────────────┬─────╮ +│Variable │Value│ +├────────────┼─────┤ +│S3a. GENDER:│Male │ +╰────────────┴─────╯ + + Custom Tables +╭────────────────────────────────────────────────────────────────────────┬─────╮ +│ │Count│ +├────────────────────────────────────────────────────────────────────────┼─────┤ +│105b. How likely is it that drivers who have had too much Almost │ 297│ +│to drink to drive safely will A. Get stopped by the police? certain │ │ +│ Very likely │ 660│ +│ Somewhat │ 1174│ +│ likely │ │ +│ Somewhat │ 640│ +│ unlikely │ │ +│ Very │ 311│ +│ unlikely │ │ +╰────────────────────────────────────────────────────────────────────────┴─────╯ + + Split Values +╭────────────┬──────╮ +│Variable │ Value│ +├────────────┼──────┤ +│S3a. GENDER:│Female│ +╰────────────┴──────╯ + + Custom Tables +╭────────────────────────────────────────────────────────────────────────┬─────╮ +│ │Count│ +├────────────────────────────────────────────────────────────────────────┼─────┤ +│105b. How likely is it that drivers who have had too much Almost │ 403│ +│to drink to drive safely will A. Get stopped by the police? certain │ │ +│ Very likely │ 842│ +│ Somewhat │ 1589│ +│ likely │ │ +│ Somewhat │ 667│ +│ unlikely │ │ +│ Very │ 298│ +│ unlikely │ │ +╰────────────────────────────────────────────────────────────────────────┴─────╯ +]) +AT_CLEANUP -- 2.30.2