Skip to content

Add a by attribute to data_tabulate() objects when by is present - #690

Merged
etiennebacher merged 13 commits into
easystats:mainfrom
elinw:by
Jun 19, 2026
Merged

Add a by attribute to data_tabulate() objects when by is present#690
etiennebacher merged 13 commits into
easystats:mainfrom
elinw:by

Conversation

@elinw

@elinw elinw commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

I wasn't sure if you would want an additional test; all the current tests are still passing.
The attributes aren't listing in the documentation so I didn't change anything there.

Closes #688

@etiennebacher etiennebacher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Yes please add at least one test for this.

Comment thread R/data_tabulate.R Outdated
Comment thread R/data_tabulate.R Outdated
Comment thread NEWS.md Outdated
@etiennebacher etiennebacher changed the title Add a by attribute to data_tabulate objects when a by is present Add a by attribute to 1data_tabulate() objects when by` is present Jun 14, 2026
@etiennebacher etiennebacher changed the title Add a by attribute to 1data_tabulate() objects when by` is present Add a by attribute to data_tabulate() objects when by is present Jun 14, 2026
@elinw

elinw commented Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

Also the linter wanted me to make some changes and then not make them (when I made them it told me to change them back) unless I misunderstood.

@elinw
elinw requested a review from etiennebacher June 15, 2026 19:30
Comment thread R/data_tabulate.R
if (is.null(by)) {
class(out) <- c("datawizard_tables", "list")
} else {
out <- lapply(out, structure, by = by_name)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why this attribute needs to be added to each element in out. Below we add the attribute collapse to out only, why can't we do that for by since it has the same value for all elements in out anyway?

@elinw elinw Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this is what took me a long time to figure out. "by" is really a property of individual tables not of the list. This should be consistent whether you get the table through the data.frame method or through the default method or if select has one or multiple columns. Also it should be the same for grouped data frames.

It took me a while to see this, which was why I would get the tests to work on default and then they would fail or data.frame or with multiple columns.
As a practical matter, if you pull out one table from the list you should get the "by" along with it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I'm convinced.

(Re your comment about "Requested changes" below, this is because Github keeps this label until the same person approves the PR.)

Comment thread tests/testthat/test-data_tabulate.R Outdated
@elinw

This comment was marked as off-topic.

@elinw

elinw commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

wrong branch

@elinw
elinw requested a review from etiennebacher June 19, 2026 17:48
@elinw

elinw commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

I'm not sure if there is a change I missed but it is still showing one requested change . I can't tell what it is or if it was actually resolved.

@etiennebacher
etiennebacher merged commit 3e7ccbd into easystats:main Jun 19, 2026
25 checks passed
@strengejacke

Copy link
Copy Markdown
Member

Please remember to increase the version number in the fourth place by one for "user visible" changes (e.g. to 1.3.1.x) in the description file. This ensures that easystats::install_latest() Will work as intended.

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.

Add by attribute to cross_tab and cross_tabs objects

3 participants