Skip to content

Tabulate FACET row groups - #594

Open
teunbrand wants to merge 27 commits into
table-featurefrom
tabulate_facet_groups
Open

teunbrand wants to merge 27 commits into
table-featurefrom
tabulate_facet_groups

Conversation

@teunbrand

Copy link
Copy Markdown
Collaborator

This PR brings in the FACET clause for grouping purposes.
I've left out the aggregation utility proposed for facets, because I think they can do with a little more discussion.

Essentially the facet clause designates columns to be group headings, and these either get rendered as interleaved group label rows, or as group label columns.

Our FACET foo roughly corresponds to gt(groupname_col = "foo") and FACET SETTING place => 'left' to tab_options(row_group.as_column = TRUE).

In contrast to VISUALISE ... FACET, I've allowed multiple variables, which means we might miss out on SCALE panel ..., but I'm content with that for now.

In contrast to gt's grouping logic, we do not collapse labels of multiple variables by default. Multiple nesting levels are displayed as separate rows or columns by default. A separator argument can be used to concatenate the labels.

Assign each result row a group id from its facet values (nested by
variable, nulls in one group per level), reorder rows so groups are
contiguous, and stamp body rows with their group id for label-cell
generation.
Faceted tables emit one GroupHeading row per changed facet-variable
level above each group (hierarchical for several variables), with
labels read from the group's first formatted row; the facet columns
leave the body. Column-claim conflicts (SPAN/STUB over a facet
variable) are rejected by Table::validate_boundaries. place => 'left'
is rejected until group-stub columns land.
Nulls in a facet variable form their own group, sorted first or last, or
their rows are dropped from the table; default 'last'.
Joins nested group labels into one ('north - q1'), collapsing label rows
or group stub columns to a single level.
@teunbrand

This comment was marked as resolved.

Comment thread doc/syntax/clause/facet-tabulate.qmd Resolved
Comment thread src/execute/table/facet.rs Resolved
Comment thread src/table/facet.rs Resolved
Comment thread src/writer/html.rs Resolved
Comment thread src/parser/builder.rs Resolved
Comment thread src/validate.rs Resolved
Comment thread src/table/facet.rs Resolved
@thomasp85

This comment was marked as resolved.

Comment thread src/table/layout.rs Resolved
@teunbrand

This comment was marked as resolved.

@teunbrand teunbrand mentioned this pull request Nov 4, 2026
@teunbrand

Copy link
Copy Markdown
Collaborator Author

That is most review comments resolved.
Now rendering multiple elements with properly scoped row headers.
Still have to decide on where some shared plot/table facet machinery should live, in particular the facet AST and the LevelKey/FacetLevel logic I've adopted here. They currently live in the plot directory, but might need their own src/facet.rs or something.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants