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

It should not fail when lumping empty group with weight #294

Closed
holgerbrandl opened this issue Jan 12, 2022 · 2 comments
Closed

It should not fail when lumping empty group with weight #294

holgerbrandl opened this issue Jan 12, 2022 · 2 comments

Comments

@holgerbrandl
Copy link

When using fct_lump on a grouped data frame with a weighting attribute, it should not fail if a group is empty.

Example

iris %>% 
  group_by(Species) %>% filter(Species == "virginica") %>% 
  mutate(Species_Lumped = forcats::fct_lump(Species, w = Speal.Length, prop = 0.04))

This fails using v0.5.1 with

Error: Problem with `mutate()` column `Species_Lumped`.
i `Species_Lumped = forcats::fct_lump(Species, w = Sepal.Length, prop = 0.04)`.
x missing value where TRUE/FALSE needed
i The error occurred in group 1: Species = virginica.
Run `rlang::last_error()` to see where the error occurred

Tested with R version 4.1.2 (2021-11-01)

@holgerbrandl holgerbrandl changed the title It should fail when lumping empty group with weight It should not fail when lumping empty group with weight Jan 12, 2022
@xxspurs

This comment was marked as off-topic.

@hadley
Copy link
Member

hadley commented Mar 2, 2022

Reprex:

library(dplyr, warn.conflicts = FALSE)

iris %>% 
  group_by(Species) %>% 
  filter(Species == "virginica") %>% 
  mutate(Species_Lumped = forcats::fct_lump(Species, w = Sepal.Length, prop = 0.04))
#> Error in `mutate()`:
#> ! Problem while computing `Species_Lumped = forcats::fct_lump(Species, w
#>   = Sepal.Length, prop = 0.04)`.
#> ℹ The error occurred in group 1: Species = virginica.
#> Caused by error in `if (prop > 0 && sum(prop_n <= prop) <= 1) ...`:
#> ! missing value where TRUE/FALSE needed

Created on 2022-03-02 by the reprex package (v2.0.1)

Duplicate of #292

@hadley hadley closed this as completed Mar 2, 2022
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

No branches or pull requests

3 participants