Skip to content

Commit

Permalink
Added summarise<fable>() support
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchelloharawild committed Jul 3, 2020
1 parent 6653e23 commit 4b71ea8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ S3method(stream,lst_mdl)
S3method(stream,mdl_df)
S3method(stream,mdl_ts)
S3method(stream,null_mdl)
S3method(summarise,fbl_ts)
S3method(summarise,grouped_fbl)
S3method(tidy,mdl_df)
S3method(tidy,mdl_ts)
S3method(tidy,null_mdl)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
and `generate()`).
* Improved equality comparison of `agg_vec` classes, aggregated values will now
always match regardless of the value used.
* Using `summarise()` with a fable will now retain the fable class if the
distribution still exists under the same variable name.
* Documentation improvements
* Performance improvements

Expand Down
20 changes: 20 additions & 0 deletions R/dplyr-fable.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,23 @@ dplyr_reconstruct.fbl_ts <- function(data, template) {

#' @export
dplyr_reconstruct.grouped_fbl <- dplyr_reconstruct.fbl_ts

#' @export
summarise.fbl_ts <- function(.data, ..., .groups = NULL) {
dist_var <- distribution_var(.data)
dist_ptype <- vec_ptype(.data[[dist_var]])
resp_var <- response_vars(.data)
.data <- summarise(as_tsibble(.data), ..., .groups = .groups)

# If the distribution is lost, return a tsibble
if(dist_var %in% names(.data)) {
if(!vec_is(.data[[dist_var]], dist_ptype)){
return(.data)
}
}

build_fable(.data, response = resp_var, distribution = dist_var)
}

#' @export
summarise.grouped_fbl <- summarise.fbl_ts

0 comments on commit 4b71ea8

Please sign in to comment.