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

.drop missing in Usage of ?count #6820

Closed
LukasWallrich opened this issue Apr 9, 2023 · 2 comments · Fixed by #6826
Closed

.drop missing in Usage of ?count #6820

LukasWallrich opened this issue Apr 9, 2023 · 2 comments · Fixed by #6826

Comments

@LukasWallrich
Copy link

Maybe I misunderstand the Usage section, but it seems to me that .drop should be in the Usage section of ?count ... when I searched for a way to keep empty levels, I first looked there and then initially gave up on using count()

@eipi10
Copy link
Contributor

eipi10 commented Apr 13, 2023

.drop isn't included in the usage section of the help, which is probably an oversight that should be corrected, but count does accept a .drop argument (see the reprex below for an example). If you scroll down a bit further in the help for count, there's documentation for the .drop argument and its usage in count.

library(tidyverse)

d = mtcars

d = d %>% mutate(cyl = fct_expand(factor(cyl), "10")) 
levels(d$cyl)
#> [1] "4"  "6"  "8"  "10"

d %>% count(cyl)
#>   cyl  n
#> 1   4 11
#> 2   6  7
#> 3   8 14

d %>% count(cyl, .drop=FALSE)
#>   cyl  n
#> 1   4 11
#> 2   6  7
#> 3   8 14
#> 4  10  0

Created on 2023-04-12 with reprex v2.0.2

@nstjhp
Copy link

nstjhp commented Apr 17, 2023

You're right and I've been bitten by this before when quickly scanning function arguments to find if count could do what I wanted. I think it was just forgotten about when the tidyverse team made the function generic in 2020 (#5633). If the team have time to correct this, it would also be nice to add an example with the .drop argument in the Examples section to increase its visibility.

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 a pull request may close this issue.

3 participants