Skip to content

Commit

Permalink
Drop fable/mable structure if a join operation produces invalid object
Browse files Browse the repository at this point in the history
Ref: #296
  • Loading branch information
mitchelloharawild committed Jan 7, 2021
1 parent 4d89377 commit 08bbd03
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion R/dplyr-fable.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ dplyr_col_modify.grouped_fbl <- dplyr_col_modify.fbl_ts
#' @export
dplyr_reconstruct.fbl_ts <- function(data, template) {
res <- NextMethod()
build_fable(res, response = response_vars(template), distribution = distribution_var(template))
dist <- distribution_var(template)
if(dist %in% names(res)) {
build_fable(res, response = response_vars(template), distribution = dist)
} else {
res
}
}

#' @export
Expand Down
7 changes: 6 additions & 1 deletion R/dplyr-mable.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,10 @@ dplyr_col_modify.mdl_df <- function(data, cols) {
dplyr_reconstruct.mdl_df <- function(data, template) {
res <- NextMethod()
mbl_vars <- names(which(vapply(data, inherits, logical(1L), "lst_mdl")))
build_mable(data, key = !!key_vars(template), model = !!mbl_vars)
kv <- key_vars(template)
if(all(kv %in% names(res))) {
build_mable(data, key = !!kv, model = !!mbl_vars)
} else {
as_tibble(res)
}
}

0 comments on commit 08bbd03

Please sign in to comment.