-
Notifications
You must be signed in to change notification settings - Fork 420
Open
Labels
featurea feature request or enhancementa feature request or enhancement
Description
I was thinking of this when implementing #1461 but wasn't sure if it would be useful.
But now I think it can be useful because whenever I call chop() I often think of what i want to "chop by" when i say it out loud in my head.
library(ivs)
library(dplyr, warn.conflicts = FALSE)
df <- tibble(
id=c(rep("a",4),rep("b",2),rep("c",3)),
start=c(100,250,400,600,150,610,275,600,700),
end=c(200,300,550,650,275,640,325,675,725)
)
df <- df %>%
mutate(range = iv(start, end), .keep = "unused")
df
#> # A tibble: 9 × 2
#> id range
#> <chr> <iv<dbl>>
#> 1 a [100, 200)
#> 2 a [250, 300)
#> 3 a [400, 550)
#> 4 a [600, 650)
#> 5 b [150, 275)
#> 6 b [610, 640)
#> 7 c [275, 325)
#> 8 c [600, 675)
#> 9 c [700, 725)
df %>%
tidyr::chop(range)
#> # A tibble: 3 × 2
#> id range
#> <chr> <list<iv<dbl>>>
#> 1 a [4]
#> 2 b [2]
#> 3 c [3]Like in this example I think it makes the most sense to say that I want to chop "by id".
If I say I want to "chop the range", you still have to ask yourself what you want to chop it by, so you implicitly always need that "by" knowledge loaded in your head anyways, so we might as well let you specify that directly instead.
Notes:
- Signature change to
chop(data, cols = NULL, ..., by = NULL), socolsis now technically optional - If one of
colsorbyis supplied, the other is inferred as "everything else" - We have decided in
nest()thatnest(data)with no other args means "nest everything" so we probably want to either be consistent with that here (i.e. "chop everything") or say that you must specify at least one ofcolsorby, which does feel safer. - Allow for both
colsandbyto be specified together, likenest() - Can probably borrow a lot from
nest_info()? Probably worth trying to harmonize that between the two functions
Metadata
Metadata
Assignees
Labels
featurea feature request or enhancementa feature request or enhancement