CTABLES split file
authorBen Pfaff <blp@cs.stanford.edu>
Fri, 12 Aug 2022 19:59:02 +0000 (12:59 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Fri, 12 Aug 2022 19:59:12 +0000 (12:59 -0700)
src/language/stats/ctables.c
tests/language/stats/ctables.at

index 2611bfebb3a53cbc21fb18e9ce9f546790b2c0e7..fd296a00216e5165bcbe9427fc79cd99ccf71128 100644 (file)
@@ -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);
index 12caa73d3b3c0b57bacb64900f091c950e88224a..4bdd1744ff72901981e824a10f45499c12de1396 100644 (file)
@@ -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