Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tabyl label #575

Merged
merged 11 commits into from
Jun 27, 2024
Merged

Tabyl label #575

merged 11 commits into from
Jun 27, 2024

Conversation

olivroy
Copy link
Contributor

@olivroy olivroy commented May 23, 2024

Description

Addresses #563 (comment)

SImply default to label attribute if it exists when displaying tabyl.

It enables this by default, which is a breaking change? But I wouldn't see why you would not want that if you took care of labelling your variables.

More fiddling required than expected since a lot of base R functions drop attributes subset(), split(), as.character(), etc.

A solution to get the previous behavior is the following (or haven::zap_labels() or similar.

tabyl(mt_label %>% labelled::remove_var_label(), cyl)

Related Issue

Partially addresses #394. Doesn't solve the value labels part, only variable label.

Example

  mt_label <- mtcars
  attr(mt_label$cyl, "label") <- "Number of cyl"
# before 
tabyl(mt_label, cyl)
 cyl  n percent
   4 11 0.34375
   6  7 0.21875
   8 14 0.43750
# this pr 
tabyl(mt_label, cyl)
 Number of cyl  n percent
             4 11 0.34375
             6  7 0.21875
             8 14 0.43750

Copy link

codecov bot commented May 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (3769ab0) to head (88957ce).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##              main      #575    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           27        27            
  Lines         1274      1401   +127     
==========================================
+ Hits          1274      1401   +127     
Files Coverage Δ
R/get_dupes.R 100.00% <ø> (ø)
R/print_tabyl.R 100.00% <ø> (ø)
R/tabyl.R 100.00% <100.00%> (ø)

... and 15 files with indirect coverage changes

Copy link
Owner

@sfirke sfirke left a comment

Choose a reason for hiding this comment

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

Outstanding! Easy to follow, thank you. I just suggested teeny comment changes.

R/tabyl.R Outdated Show resolved Hide resolved
R/tabyl.R Outdated Show resolved Hide resolved
@sfirke
Copy link
Owner

sfirke commented Jun 27, 2024

This is great @olivroy, sorry for delay in review. When we merge this we can see if the Codecov error #576 is fixed 😁

It enables this by default, which is a breaking change? But I wouldn't see why you would not want that if you took care of labelling your variables.

Agree and agree... the next release of janitor should probably be 3.0.0 given that this is a breaking change and that so much time has elapsed. I do expect it could cause pain even if it's an improvement if it breaks existing code.

More fiddling required than expected since a lot of base R functions drop attributes subset(), split(), as.character(), etc.

Yes this is irritating. #527 would at least address the tidyverse functions doing this, I think.

A solution to get the previous behavior is the following (or haven::zap_labels() or similar.

Could you add that workaround to NEWS.md in this PR and move this contribution from "New features" to "Breaking changes"?

Co-authored-by: Sam Firke <sfirke@users.noreply.github.com>
NEWS.md Outdated Show resolved Hide resolved
@olivroy
Copy link
Contributor Author

olivroy commented Jun 27, 2024

Thanks so much for the review and the kind words! I am very glad my code was easy to follow, but I have to thank you and Bill for that. janitor is one of the first packages I contributed to!

It is a breaking change, but only in display. I don't think many people will pipe much after. And IIRC, the original names are kept in tabyl.

Let me know if you want me to add other documentation, or tests, or do more verification!

NEWS.md Outdated Show resolved Hide resolved
@olivroy
Copy link
Contributor Author

olivroy commented Jun 27, 2024

This will work well with #564 as in my experience, names when you read from Excel in particular tend to be more human readable, the ability to keep those and then use them automatically for tabyl() is an improvement in my opinion!

NEWS.md Outdated Show resolved Hide resolved
@sfirke sfirke merged commit cd47202 into sfirke:main Jun 27, 2024
9 checks passed
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.

None yet

2 participants