tidyverts / fabletools

General fable features useful for extension packages
http://fabletools.tidyverts.org/
89 stars 31 forks source link

Aggregating an <aggregated> value crashes R #270

Closed mitchelloharawild closed 4 years ago

mitchelloharawild commented 4 years ago
library(fpp3)
B1 <- rnorm(12, mean = 5) + (1:12)
B2 <- rnorm(12, mean = 5)
M2 <- rnorm(12, mean = 25)

ts_data <- tibble(value = c(B1, B2, M2), 
                  month = rep(yearmonth(paste("2020", 1:12, sep="-")), 3), 
                  B = agg_vec(c(rep("B1", 12), rep("B2", 12), rep(NA, 12)), c(rep(FALSE, 24), rep(TRUE, 12))), 
                  M = c(rep("M1", 24), rep("M2", 12))) %>%
  as_tsibble(key = c("B", "M"), index = month)

ts_data %>%
  # Specify hierarchy
  aggregate_key(M / B, value = sum(value))
mitchelloharawild commented 4 years ago

cc @GeorgeAthana

mitchelloharawild commented 4 years ago

MRE:

tibble(A = fabletools:::agg_vec(letters)) %>% 
  group_by(A = fabletools:::agg_vec(A))