collapse icon indicating copy to clipboard operation
collapse copied to clipboard

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

Open arthurgailes opened this issue 1 year ago • 3 comments

arthurgailes avatar Apr 23 '24 13:04 arthurgailes

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.

arthurgailes avatar Apr 23 '24 13:04 arthurgailes

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.

SebKrantz avatar Apr 23 '24 18:04 SebKrantz

Sure thing. Perhaps something like:

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

arthurgailes avatar Apr 23 '24 20:04 arthurgailes