Skip to content

Commit

Permalink
Fixes #14: Compatability with broom 0.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mdancho84 committed Jun 8, 2020
1 parent 73ae651 commit 3e02a80
Show file tree
Hide file tree
Showing 28 changed files with 68 additions and 56 deletions.
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: sweep
Type: Package
Title: Tidy Tools for Forecasting
Version: 0.2.2.9000
Version: 0.2.3
Date: 2019-10-08
Authors@R: c(
person("Matt", "Dancho", email = "[email protected]", role = c("aut", "cre")),
Expand All @@ -26,11 +26,11 @@ Imports:
broom (>= 0.4.2),
dplyr (>= 0.7.0),
forecast (>= 8.0),
lazyeval (>= 0.2.0),
lubridate (>= 1.6.0),
tibble (>= 1.2),
tidyr (>= 1.0.0),
timetk (>= 0.1.0)
timetk (>= 2.0.0),
rlang
Suggests:
forcats,
knitr,
Expand All @@ -44,6 +44,6 @@ Suggests:
tidyquant,
tidyverse,
fracdiff
RoxygenNote: 6.1.1
RoxygenNote: 7.1.0
Roxygen: list(markdown = TRUE)
VignetteBuilder: knitr
5 changes: 4 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# sweep 0.2.1.9999
# sweep 0.2.3
* Fixes for compatability with `broom` v0.7.0

# sweep 0.2.2
* Fixes for compatability with `tidyquant` v0.5.7

# sweep 0.2.1
Expand Down
2 changes: 1 addition & 1 deletion R/global_vars.R
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
globalVariables(c(".", "value", "observed", "season", ".actual", ".fitted",
"actual", "seasonal", "trend", "remainder", "ret", "..target"))
"actual", "seasonal", "trend", "remainder", "ret", "..target", "key"))
2 changes: 1 addition & 1 deletion R/sw_augment.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#'
#' Note that by convention the first argument is almost always \code{data},
#' which specifies the original data object. This is not part of the S3
#' signature, partly because it prevents \link{rowwise_df_tidiers} from
#' signature, partly because it prevents rowwise_df_tidiers from
#' taking a column name as the first argument.
#'
#' @seealso [broom::augment()]
Expand Down
6 changes: 3 additions & 3 deletions R/sw_sweep.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ sw_sweep.forecast <- function(x, fitted = FALSE, timetk_idx = FALSE, rename_inde
n <- length(x$mean)
future_idx <- ret_x %>%
timetk::tk_index() %>%
timetk::tk_make_future_timeseries(n_future = 2*n + 50, ...)
timetk::tk_make_future_timeseries(length_out = n, ...)
future_idx <- future_idx[1:n]
ret_mean <- tk_tbl(x$mean, preserve_index = TRUE, rename_index = rename_index, silent = TRUE)
ret_mean[, rename_index] <- future_idx
Expand Down Expand Up @@ -147,14 +147,14 @@ sw_sweep.forecast <- function(x, fitted = FALSE, timetk_idx = FALSE, rename_inde
ret <- ret_x
if (fitted) {
ret <- rbind(ret_x, ret_fit) %>%
dplyr::select_(rename_index, "key", "dplyr::everything()")
dplyr::select(!! rlang::sym(rename_index), key, dplyr::everything())
}
if (ncol(ret) != ncol(ret_fcast)) {
colnames_to_add <- colnames(ret_fcast)[!(colnames(ret_fcast) %in% colnames(ret))]
for (i in seq_along(colnames_to_add)) ret[,colnames_to_add[i]] <- NA
}
ret <- rbind(ret, ret_fcast) %>%
dplyr::select_(rename_index, "key", "dplyr::everything()")
dplyr::select(!! rlang::sym(rename_index), key, dplyr::everything())

return(ret)
}
Expand Down
4 changes: 3 additions & 1 deletion R/sweep-package.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#' sweep: Extending broom to time series forecasting
#'
#' @details
#' @description
#' The `sweep` package "tidies" up the
#' modeling workflow of the `forecast` package.
#'
#' @details
#' The model and forecast objects are not covered by
#' the `broom` package. It includes the [sw_tidy()], [sw_glance()],
#' and [sw_augment()] functions that work in a similar capacity as `broom` functions.
Expand Down
2 changes: 1 addition & 1 deletion R/tidiers_arima.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ sw_glance.Arima <- function(x, ...) {

# Summary statistics
ret_2 <- tibble::tibble(sigma = sqrt(x$sigma2))
ret_2 <- broom::finish_glance(ret_2, x) %>%
ret_2 <- finish_glance(ret_2, x) %>%
tibble::as_tibble()

# forecast accuracy
Expand Down
2 changes: 1 addition & 1 deletion R/tidiers_ets.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ sw_glance.ets <- function(x, ...) {

# Summary statistics
ret_2 <- tibble::tibble(sigma = sqrt(x$sigma2))
ret_2 <- broom::finish_glance(ret_2, x) %>%
ret_2 <- finish_glance(ret_2, x) %>%
tibble::as_tibble()

# forecast accuracy
Expand Down
2 changes: 1 addition & 1 deletion R/tidiers_robets.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ sw_glance.robets <- function(x, ...) {

# Summary statistics
ret_2 <- tibble::tibble(sigma = sqrt(x$sigma2))
ret_2 <- broom::finish_glance(ret_2, x) %>%
ret_2 <- finish_glance(ret_2, x) %>%
tibble::as_tibble()

# # forecast accuracy
Expand Down
21 changes: 21 additions & 0 deletions R/utils-broom.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,24 @@ add_index <- function(ret, rename_index) {

#' @export
dplyr::`%>%`


# The old broom::finish_glance() function
# https://github.com/tidymodels/broom/pull/597
finish_glance <- function(ret, x) {
ret$logLik <- tryCatch(as.numeric(stats::logLik(x)), error = function(e) NULL)
ret$AIC <- tryCatch(stats::AIC(x), error = function(e) NULL)
ret$BIC <- tryCatch(stats::BIC(x), error = function(e) NULL)

# special case for REML objects (better way?)
if (inherits(x, "lmerMod")) {
ret$deviance <- tryCatch(stats::deviance(x, REML = FALSE),
error = function(e) NULL
)
} else {
ret$deviance <- tryCatch(stats::deviance(x), error = function(e) NULL)
}
ret$df.residual <- tryCatch(stats::df.residual(x), error = function(e) NULL)

tibble::as_tibble(ret, rownames = NULL)
}
2 changes: 1 addition & 1 deletion man/arima_string.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/bats_string.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions man/bike_sales.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/sw_augment.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/sw_sweep.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions man/sweep_package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/tbats_string.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions man/tidiers_HoltWinters.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/tidiers_StructTS.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/tidiers_arima.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions man/tidiers_bats.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/tidiers_decomposed_ts.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions man/tidiers_ets.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/tidiers_nnetar.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions man/tidiers_robets.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions man/tidiers_stl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions sweep.Rproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ StripTrailingWhitespace: Yes
BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageRoxygenize: rd,collate,namespace
4 changes: 2 additions & 2 deletions tests/testthat/test_tidiers_lm.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test_that("sw_*.default test returns tibble with correct rows and columns.", {
expect_is(test, "tbl")
# expect_false(any(lapply(test, is.factor) %>% unlist())) # No factors
expect_equal(nrow(test), 1)
expect_equal(ncol(test), 11)
expect_equal(ncol(test), 12)

# sw_augment ----
test <-
Expand All @@ -29,6 +29,6 @@ test_that("sw_*.default test returns tibble with correct rows and columns.", {
expect_is(test, "tbl")
# expect_false(any(lapply(test, is.factor) %>% unlist())) # No factors
expect_equal(nrow(test), 32)
expect_equal(ncol(test), 9)
expect_equal(ncol(test), 8)

})

0 comments on commit 3e02a80

Please sign in to comment.