return false;
struct ctables_categories *c = xmalloc (sizeof *c);
- *c = (struct ctables_categories) { .n_refs = n_vars };
+ *c = (struct ctables_categories) { .n_refs = n_vars, .show_empty = true };
for (size_t i = 0; i < n_vars; i++)
{
struct ctables_categories **cp
enum pivot_axis_type a, size_t a_idx)
{
if (a >= PIVOT_N_AXES)
- {
-
- }
- else if (!s->nests[a] || idx >= s->nests[a]->n)
- {
-
-
- }
+ ctables_cell_insert__ (s, c, cats);
+ else if (!s->nests[a] || a_idx >= s->nests[a]->n)
+ ctables_section_recurse_add_empty_categories (s, cats, c, a + 1, 0);
else
{
-
- for (size_t i = 0; i < s->nests[a]->n; i++)
-
+ const struct variable *var = s->nests[a]->vars[a_idx];
+ int width = var_get_width (var);
+ const struct hmap *occurrences = &s->occurrences[a][a_idx];
+ const struct ctables_section_value *sv;
+ HMAP_FOR_EACH (sv, struct ctables_section_value, node, occurrences)
+ {
+ union value *value = case_data_rw (c, var);
+ value_destroy (value, width);
+ value_clone (value, &sv->value, width);
+ cats[a][a_idx] = ctables_categories_match (
+ s->table->categories[var_get_dict_index (var)], value, var);
+ assert (cats[a][a_idx] != NULL);
+ ctables_section_recurse_add_empty_categories (s, cats, c, a, a_idx + 1);
+ }
}
}
const struct ctables_category *cats[PIVOT_N_AXES][10]; /* XXX */
struct ccase *c = case_create (dict_get_proto (s->table->ctables->dict));
- ctables_section_recurse_add_empty_categories (s, c, cats, a, 0);
+ ctables_section_recurse_add_empty_categories (s, cats, c, 0, 0);
+ case_unref (c);
}
static bool
.n_refs = n_vars,
.cats = cat,
.n_cats = 1,
+ .show_empty = true,
};
struct ctables_categories **categories = xnmalloc (n_vars,
dnl * String values
dnl * Date values
dnl * Data-dependent sorting.
-dnl - EMPTY=INCLUDE.
dnl - TITLES: )DATE, )TIME, )TABLE.
dnl - SIGTEST
dnl - COMPARETEST
])
AT_CLEANUP
+AT_SETUP([CTABLES show or hide empty categories])
+AT_CHECK([ln $top_srcdir/examples/nhtsa.sav . || cp $top_srcdir/examples/nhtsa.sav .])
+AT_DATA([ctables.sps],
+[[GET 'nhtsa.sav'.
+IF (qn105ba = 2) qn105ba = 1.
+IF (qns3a = 1) qns3a = 2.
+CTABLES /TABLE qn105ba BY qns3a [COLPCT PCT8.0].
+CTABLES /TABLE qn105ba BY qns3a [COLPCT PCT8.0]
+ /CATEGORIES VAR=qn105ba EMPTY=EXCLUDE.
+CTABLES /TABLE qn105ba BY qns3a [COLPCT PCT8.0]
+ /CATEGORIES VAR=qns3a EMPTY=EXCLUDE.
+CTABLES /TABLE qn105ba BY qns3a [COLPCT PCT8.0]
+ /CATEGORIES VAR=ALL EMPTY=EXCLUDE.
+]])
+AT_CHECK([pspp ctables.sps -O box=unicode -O width=80], [0], [dnl
+ Custom Tables
+╭──────────────────────────────────────────────────────────────┬───────────────╮
+│ │ S3a. GENDER: │
+│ ├───────┬───────┤
+│ │ Male │ Female│
+│ ├───────┼───────┤
+│ │ Column│ Column│
+│ │ % │ % │
+├──────────────────────────────────────────────────────────────┼───────┼───────┤
+│105b. How likely is it that drivers who have had Almost │ .│ 32%│
+│too much to drink to drive safely will A. Get certain │ │ │
+│stopped by the police? Very likely│ .│ 0%│
+│ Somewhat │ .│ 40%│
+│ likely │ │ │
+│ Somewhat │ .│ 19%│
+│ unlikely │ │ │
+│ Very │ .│ 9%│
+│ unlikely │ │ │
+╰──────────────────────────────────────────────────────────────┴───────┴───────╯
+
+ Custom Tables
+╭──────────────────────────────────────────────────────────────┬───────────────╮
+│ │ S3a. GENDER: │
+│ ├───────┬───────┤
+│ │ Male │ Female│
+│ ├───────┼───────┤
+│ │ Column│ Column│
+│ │ % │ % │
+├──────────────────────────────────────────────────────────────┼───────┼───────┤
+│105b. How likely is it that drivers who have had Almost │ .│ 32%│
+│too much to drink to drive safely will A. Get certain │ │ │
+│stopped by the police? Somewhat │ .│ 40%│
+│ likely │ │ │
+│ Somewhat │ .│ 19%│
+│ unlikely │ │ │
+│ Very │ .│ 9%│
+│ unlikely │ │ │
+╰──────────────────────────────────────────────────────────────┴───────┴───────╯
+
+ Custom Tables
+╭────────────────────────────────────────────────────────────────────┬─────────╮
+│ │ S3a. │
+│ │ GENDER: │
+│ ├─────────┤
+│ │ Female │
+│ ├─────────┤
+│ │ Column %│
+├────────────────────────────────────────────────────────────────────┼─────────┤
+│105b. How likely is it that drivers who have had too Almost │ 32%│
+│much to drink to drive safely will A. Get stopped by certain │ │
+│the police? Very likely │ 0%│
+│ Somewhat │ 40%│
+│ likely │ │
+│ Somewhat │ 19%│
+│ unlikely │ │
+│ Very │ 9%│
+│ unlikely │ │
+╰────────────────────────────────────────────────────────────────────┴─────────╯
+
+ Custom Tables
+╭────────────────────────────────────────────────────────────────────┬─────────╮
+│ │ S3a. │
+│ │ GENDER: │
+│ ├─────────┤
+│ │ Female │
+│ ├─────────┤
+│ │ Column %│
+├────────────────────────────────────────────────────────────────────┼─────────┤
+│105b. How likely is it that drivers who have had too Almost │ 32%│
+│much to drink to drive safely will A. Get stopped by certain │ │
+│the police? Somewhat │ 40%│
+│ likely │ │
+│ Somewhat │ 19%│
+│ unlikely │ │
+│ Very │ 9%│
+│ unlikely │ │
+╰────────────────────────────────────────────────────────────────────┴─────────╯
+])
+AT_CLEANUP
AT_SETUP([CTABLES simple nesting])
AT_CHECK([ln $top_srcdir/examples/nhtsa.sav . || cp $top_srcdir/examples/nhtsa.sav .])
[[GET 'nhtsa.sav'.
CTABLES /TABLE=qnd1 > qn1 BY qns3a.
CTABLES /TABLE=qnd1 [MINIMUM, MAXIMUM, MEAN] > qns3a > (qn26 + qn27).
-CTABLES /TABLE=qnsa1 > qn105ba [COLPCT] BY qns1.
+CTABLES /TABLE=qnsa1 > qn105ba [COLPCT] BY qns1
+ /CATEGORIES VAR=qnsa1 EMPTY=EXCLUDE.
CTABLES /TABLE=AgeGroup > qn20 [MEAN F8.1, STDDEV F8.1].
]])
AT_CHECK([pspp ctables.sps -O box=unicode -O width=80], [0], [dnl
╰─────────────────────────────────────────────────────────┴───────┴───────┴────╯
Custom Tables
-╭──────────────────────────────────┬───────────────────────────────────────────╮
-│ │S1. Including yourself, how many members of│
-│ │ this household are age 16 or older? │
-│ ├──────┬───────┬──────┬──────┬───────┬──────┤
-│ │ │ │ │ │ │ 6 or │
-│ │ 1 │ 2 │ 3 │ 4 │ 5 │ more │
-│ ├──────┼───────┼──────┼──────┼───────┼──────┤
-│ │Column│ Column│Column│Column│ Column│Column│
-│ │ % │ % │ % │ % │ % │ % │
-├──────────────────────────────────┼──────┼───────┼──────┼──────┼───────┼──────┤
-│Sa1. RDD 105b. How Almost │ 9.5%│ 8.2%│ 12.4%│ 9.9%│ 20.0%│ 23.8%│
-│SAMPLE likely is it certain │ │ │ │ │ │ │
-│SOURCE: that drivers Very │ 24.9%│ 18.5%│ 24.0%│ 26.6%│ 25.5%│ 33.3%│
-│ who have had likely │ │ │ │ │ │ │
-│ too much to Somewhat│ 38.3%│ 41.9%│ 38.6%│ 37.5%│ 36.4%│ 23.8%│
-│ drink to likely │ │ │ │ │ │ │
-│ drive safely Somewhat│ 18.1%│ 21.7%│ 16.8%│ 16.7%│ 10.9%│ 9.5%│
-│ will A. Get unlikely│ │ │ │ │ │ │
-│ stopped by Very │ 9.2%│ 9.7%│ 8.2%│ 9.4%│ 7.3%│ 9.5%│
-│ the police? unlikely│ │ │ │ │ │ │
-╰──────────────────────────────────┴──────┴───────┴──────┴──────┴───────┴──────╯
+╭─────────────────────────────┬────────────────────────────────────────────────╮
+│ │S1. Including yourself, how many members of this│
+│ │ household are age 16 or older? │
+│ ├──────┬──────┬──────┬──────┬──────┬──────┬──────┤
+│ │ │ │ │ │ │ │ 6 or │
+│ │ None │ 1 │ 2 │ 3 │ 4 │ 5 │ more │
+│ ├──────┼──────┼──────┼──────┼──────┼──────┼──────┤
+│ │Column│Column│Column│Column│Column│Column│Column│
+│ │ % │ % │ % │ % │ % │ % │ % │
+├─────────────────────────────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┤
+│Sa1. RDD 105b. Almost │ .│ 9.5%│ 8.2%│ 12.4%│ 9.9%│ 20.0%│ 23.8%│
+│SAMPLE How certain │ │ │ │ │ │ │ │
+│SOURCE: likely │ │ │ │ │ │ │ │
+│ is it Very │ .│ 24.9%│ 18.5%│ 24.0%│ 26.6%│ 25.5%│ 33.3%│
+│ that likely │ │ │ │ │ │ │ │
+│ drivers │ │ │ │ │ │ │ │
+│ who have │ │ │ │ │ │ │ │
+│ had too Somewhat│ .│ 38.3%│ 41.9%│ 38.6%│ 37.5%│ 36.4%│ 23.8%│
+│ much to likely │ │ │ │ │ │ │ │
+│ drink to │ │ │ │ │ │ │ │
+│ drive │ │ │ │ │ │ │ │
+│ safely Somewhat│ .│ 18.1%│ 21.7%│ 16.8%│ 16.7%│ 10.9%│ 9.5%│
+│ will A. unlikely│ │ │ │ │ │ │ │
+│ Get │ │ │ │ │ │ │ │
+│ stopped Very │ .│ 9.2%│ 9.7%│ 8.2%│ 9.4%│ 7.3%│ 9.5%│
+│ by the unlikely│ │ │ │ │ │ │ │
+│ police? │ │ │ │ │ │ │ │
+╰─────────────────────────────┴──────┴──────┴──────┴──────┴──────┴──────┴──────╯
Custom Tables
╭──────────────────────────────────────────────────────────────┬────┬──────────╮
╰─────────────────────────────────────────────────────────┴───────┴───────┴─────────┴───────┴────────┴──────┴──────────╯
Custom Tables
-╭────────────────────────────────────────────────────────────┬─────────────────────────────────────────────────────────╮
-│ │ S1. Including yourself, how many members of this │
-│ │ household are age 16 or older? │
-│ ├─────────┬────────┬─────────┬────────┬─────────┬─────────┤
-│ │ 1 │ 2 │ 3 │ 4 │ 5 │6 or more│
-│ ├─────────┼────────┼─────────┼────────┼─────────┼─────────┤
-│ │ Column %│Column %│ Column %│Column %│ Column %│ Column %│
-├────────────────────────────────────────────────────────────┼─────────┼────────┼─────────┼────────┼─────────┼─────────┤
-│105b. How likely is it that drivers who have had Almost │ 9.5%│ 8.2%│ 12.4%│ 9.9%│ 20.0%│ 23.8%│
-│too much to drink to drive safely will A. Get certain │ │ │ │ │ │ │
-│stopped by the police? Very likely│ 24.9%│ 18.5%│ 24.0%│ 26.6%│ 25.5%│ 33.3%│
-│ Somewhat │ 38.3%│ 41.9%│ 38.6%│ 37.5%│ 36.4%│ 23.8%│
-│ likely │ │ │ │ │ │ │
-│ Subtotal │ 72.8%│ 68.6%│ 75.0%│ 74.0%│ 81.8%│ 81.0%│
-│ Somewhat │ 18.1%│ 21.7%│ 16.8%│ 16.7%│ 10.9%│ 9.5%│
-│ unlikely │ │ │ │ │ │ │
-│ Very │ 9.2%│ 9.7%│ 8.2%│ 9.4%│ 7.3%│ 9.5%│
-│ unlikely │ │ │ │ │ │ │
-│ Subtotal │ 27.2%│ 31.4%│ 25.0%│ 26.0%│ 18.2%│ 19.0%│
-╰────────────────────────────────────────────────────────────┴─────────┴────────┴─────────┴────────┴─────────┴─────────╯
+╭────────────────────────────────────────────────────────┬─────────────────────────────────────────────────────────────╮
+│ │ S1. Including yourself, how many members of this household │
+│ │ are age 16 or older? │
+│ ├────────┬────────┬────────┬────────┬───────┬────────┬────────┤
+│ │ │ │ │ │ │ │ 6 or │
+│ │ None │ 1 │ 2 │ 3 │ 4 │ 5 │ more │
+│ ├────────┼────────┼────────┼────────┼───────┼────────┼────────┤
+│ │ │ │ │ │ Column│ │ │
+│ │Column %│Column %│Column %│Column %│ % │Column %│Column %│
+├────────────────────────────────────────────────────────┼────────┼────────┼────────┼────────┼───────┼────────┼────────┤
+│105b. How likely is it that drivers who have Almost │ .│ 9.5%│ 8.2%│ 12.4%│ 9.9%│ 20.0%│ 23.8%│
+│had too much to drink to drive safely will certain │ │ │ │ │ │ │ │
+│A. Get stopped by the police? Very likely│ .│ 24.9%│ 18.5%│ 24.0%│ 26.6%│ 25.5%│ 33.3%│
+│ Somewhat │ .│ 38.3%│ 41.9%│ 38.6%│ 37.5%│ 36.4%│ 23.8%│
+│ likely │ │ │ │ │ │ │ │
+│ Subtotal │ │ 72.8%│ 68.6%│ 75.0%│ 74.0%│ 81.8%│ 81.0%│
+│ Somewhat │ .│ 18.1%│ 21.7%│ 16.8%│ 16.7%│ 10.9%│ 9.5%│
+│ unlikely │ │ │ │ │ │ │ │
+│ Very │ .│ 9.2%│ 9.7%│ 8.2%│ 9.4%│ 7.3%│ 9.5%│
+│ unlikely │ │ │ │ │ │ │ │
+│ Subtotal │ │ 27.2%│ 31.4%│ 25.0%│ 26.0%│ 18.2%│ 19.0%│
+╰────────────────────────────────────────────────────────┴────────┴────────┴────────┴────────┴───────┴────────┴────────╯
Custom Tables
╭─────────────────────────────────────────────────────────┬────────────────────────────────────────────────────────────╮