diff --git a/R/dplyr-fable.R b/R/dplyr-fable.R index 1c8ec479..46905b81 100644 --- a/R/dplyr-fable.R +++ b/R/dplyr-fable.R @@ -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 diff --git a/R/dplyr-mable.R b/R/dplyr-mable.R index 880a3612..2e005d55 100644 --- a/R/dplyr-mable.R +++ b/R/dplyr-mable.R @@ -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) + } }