Skip to content

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

Open
elinw wants to merge 8 commits into
easystats:mainfrom
elinw:by
Open

Add a by attribute to data_tabulate() objects when by is present#690
elinw wants to merge 8 commits into
easystats:mainfrom
elinw:by

Conversation

@elinw

@elinw elinw commented Jun 12, 2026

Copy link
Copy Markdown

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
class(out) <- c("datawizard_tables", "list")
} else {
class(out) <- c("datawizard_crosstabs", "list")
attr(out, "by") <- gsub('\\"', "", by_name, fixed = TRUE)

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.

Why is the gsub() necessary?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Because in this case (but not the other) the name returns e.g. "/"Island"/". I'm not sure why or if there is a way to get the name without the escapes. I tried some ideas but there was nothing obvious to me.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Meaning when a quoted variable name is used for by.

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, should this also remove ' if one passes 'Island' in by?

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 also don't think \\ is necessary if fixed = TRUE is used

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

And actually I stupidly followed the advice from the tester and added fixed = TRUE but that was wrong, this is not fixed it just looks like fixed. So the next push will put that back.

Comment thread R/data_tabulate.R
class(out) <- c("datawizard_tables", "list")
} else {
class(out) <- c("datawizard_crosstabs", "list")
attr(out, "by") <- gsub('\\"', "", by_name, fixed = TRUE)

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.

Same

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

See above

Comment thread NEWS.md
Comment on lines +7 to +8
* `data_tabluate()` now returns an attribute "by" with the
`by` variable name when the `by` parameter is used.

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.

Suggested change
* `data_tabluate()` now returns an attribute "by" with the
`by` variable name when the `by` parameter is used.
* `data_tabulate()` now returns an attribute "by" with the
`by` variable name when the `by` parameter is used.

Also please add the PR number and your username.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Where do you want the username? As @elinw or elinw?

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.

@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
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

2 participants