SebKrantz / collapse

Advanced and Fast Data Transformation in R
https://sebkrantz.github.io/collapse/
Other
651 stars 34 forks source link

add nest param to rsplit to replicate the functionality of tidyr::nest #567

Open arthurgailes opened 5 months ago

arthurgailes commented 5 months ago

Could probably do more here, e.g. allowing for a rename of $data and unnest, but stopping here in case this is out-of-scope.

SebKrantz commented 5 months ago

Thanks. Let me thing about it for a bit. I agree that this is the most parsimonious way of adding this, but fundamentally rsplit() is a recursive function and not designed to output a data.frame. I think a better way to go would be properly implementing nest() and unnest(). So far I've seen this as unnecessary because you can simply do qTBL(mtcars) |> gby(cyl, vs, am) |> smr(list(data = list(.data))), but I can think about it.

arthurgailes commented 5 months ago

Sure thing. Perhaps something like:

fnest <- function(data, ..., .key = "data") {
  smr(
    gby(data, ...),
    setNames(list("col" = list(.data)), .key)
  )
}