Skip to content

Add by to chop() #1597

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Add by to chop() #1597

wants to merge 3 commits into from

Conversation

hrryt
Copy link

@hrryt hrryt commented May 18, 2025

Fixes #1490.

Snags:

  1. In the absence of both cols and by, should we 'chop everything' as nest() does? I have thrown an error instead.
  2. Should chop() use group vars if data is grouped, as nest() does? Would this require a generic?
  3. What should happen if a column is selected by both cols and by? For now, the name is duplicated and repaired.

An example for the latter point:

df <- tibble(x = c(1, 1, 1, 2, 2), y = c(2, 1, 2, 3, 4), z = 1:5)
nest(df, data = everything(), .by = y)
#> # A tibble: 4 × 2
#>       y data            
#>   <dbl> <list>          
#> 1     2 <tibble [2 × 3]>
#> 2     1 <tibble [1 × 3]>
#> 3     3 <tibble [1 × 3]>
#> 4     4 <tibble [1 × 3]>
chop(df, everything(), by = y)
#> New names:
#> • `y` -> `y...1`
#> • `y` -> `y...3`
#> # A tibble: 4 × 4
#>   y...1           x       y...3           z
#>   <dbl> <list<dbl>> <list<dbl>> <list<int>>
#> 1     2         [2]         [2]         [2]
#> 2     1         [1]         [1]         [1]
#> 3     3         [1]         [1]         [1]
#> 4     4         [1]         [1]         [1]

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 to chop() too
1 participant