Skip to content

Plans on adding group_map/group_modify/group_walk support? #108

@TobiRoby

Description

@TobiRoby

Love dtplyr! I am using the newest version (lazy evaluation) as often as possible.
Sadly there is no support for group_map, group_modify, group_walk functionality.

Are there any plans on adding them in the future?

Here is a failing example:

library(data.table)
library(dtplyr)
library(dplyr, warn.conflicts = FALSE)
library(stringi)

# specify size 
n <- 1e5

# generate data.table with random data
data_dt <- data.table(id=stri_rand_strings(n, 1, pattern = "[A-Z]"),
                      product=stri_rand_strings(n, 3, pattern = "[A-Z]"),
                      date=sample(seq(as.Date('2019/01/01'), as.Date('2019/04/01'), by="day"), n, replace=TRUE),
                      amount=sample(1:10000,n,replace=TRUE),
                      price=rnorm(n, mean = 100, sd = 20))

data_dt_lazy <- lazy_dt(data_dt)

lag_amount_per_group <- function(group, ...){
  group %>% 
    lazy_dt() %>%
    mutate(amount_lag7 = lag(amount, n = 7)) %>% 
    as.data.table()
}

result_dtplyr <- data_dt_lazy %>%
  arrange(date) %>%
  group_by(id) %>%
  group_modify(lag_amount_per_group) %>%
  as.data.table()

Error in UseMethod("group_split") :
no applicable method for 'group_split' applied to an object of class "c('dtplyr_step_group', 'dtplyr_step')"


Also a working example with native data.table and dplyr:

result_dtplyr <- data_dt %>%
  arrange(date) %>%
  group_by(id) %>%
  group_modify(lag_amount_per_group)

result_native_dt <- data_dt[order(date)][, lag_amount_per_group(.SD), keyby=.(id)]

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions