Skip to content

Commit c614ed8

Browse files
Remove graphics from {fabletools} - now available in {ggtime}
1 parent 1bfadbe commit c614ed8

File tree

15 files changed

+87
-407
lines changed

15 files changed

+87
-407
lines changed

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ Suggests:
6767
lubridate,
6868
urca,
6969
mvtnorm,
70-
Matrix
70+
Matrix,
71+
ggtime
7172
VignetteBuilder:
7273
knitr
7374
RdMacros:

NAMESPACE

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ S3method(as_tsibble,fbl_ts)
3333
S3method(as_tsibble,grouped_fbl)
3434
S3method(augment,mdl_df)
3535
S3method(augment,mdl_ts)
36-
S3method(autolayer,fbl_ts)
37-
S3method(autolayer,tbl_ts)
38-
S3method(autoplot,dcmp_ts)
39-
S3method(autoplot,fbl_ts)
40-
S3method(autoplot,tbl_ts)
4136
S3method(coef,mdl_df)
4237
S3method(coef,mdl_ts)
4338
S3method(common_periods,default)
@@ -85,7 +80,6 @@ S3method(forecast,null_mdl)
8580
S3method(format,agg_vec)
8681
S3method(format,lst_mdl)
8782
S3method(format,mdl_ts)
88-
S3method(fortify,fbl_ts)
8983
S3method(gather,mdl_df)
9084
S3method(generate,"NULL")
9185
S3method(generate,lst_mdl)

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# fabletools (development version)
22

3+
This release migrates graphics functionality to `{ggtime}`. The commonly used graphics functions are currently exported with a soft deprecation message. To use the `autoplot()` and `autolayer()` time series plot helper functions please include `library(ggtime)` in your code.
4+
5+
After a (very) gradual deprecation process, the `{ggtime}` dependency will be removed and the graphics functions will stop being re-exported. This deprecation process is planned to span approximately 2 years, after which explicitly using `{ggtime}` will be required.
6+
37
# fabletools 0.5.1
48

59
Compatibility release for upcoming ggplot2 4.0.0 release.

R/components.R

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
#' A dable will be returned, which will allow you to easily plot the components
77
#' and see the way in which components are combined to give forecasts.
88
#'
9+
#' The components can also be visualised using the [`autoplot()`] method provided
10+
#' by the ggtime package.
11+
#'
912
#' @param object A mable.
1013
#' @param ... Other arguments passed to methods.
1114
#'
@@ -16,9 +19,8 @@
1619
#' # Forecasting with an ETS(M,Ad,A) model to Australian beer production
1720
#' aus_production %>%
1821
#' model(ets = ETS(log(Beer) ~ error("M") + trend("Ad") + season("A"))) %>%
19-
#' components() %>%
20-
#' autoplot()
21-
#'
22+
#' components()
23+
#'
2224
#' @rdname components
2325
#' @export
2426
components.mdl_df <- function(object, ...){

R/dable.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#' data structure for representing decompositions. This data class is useful for
55
#' representing decompositions, as its print method describes how its columns
66
#' can be combined to produce the original data, and has a more appropriate
7-
#' `autoplot()` method for displaying decompositions. Beyond this, a dable
8-
#' (`dcmp_ts`) behaves very similarly to a tsibble (`tbl_ts`).
7+
#' `autoplot()` method for displaying decompositions provided by ggtime.
8+
#' Beyond this, a dable (`dcmp_ts`) behaves very similarly to a tsibble (`tbl_ts`).
99
#'
1010
#' @param ... Arguments passed to [tsibble::tsibble()].
1111
#' @param response The name of the response variable column.

R/model_decomposition.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ Please check that you have specified the decomposition models appropriately.")
101101
#' library(feasts)
102102
#' library(tsibble)
103103
#' library(dplyr)
104+
#' library(ggtime)
104105
#'
105106
#' vic_food <- tsibbledata::aus_retail %>%
106107
#' filter(State == "Victoria", Industry == "Food retailing")

R/plot.R

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@
1717
#' autoplot(vars(Close, log(Close)))
1818
#'
1919
#' @importFrom ggplot2 ggplot aes geom_line guides guide_legend xlab
20-
#' @export
2120
autoplot.tbl_ts <- function(object, .vars = NULL, ...){
21+
lifecycle::deprecate_soft(
22+
when = "0.6.0",
23+
what = "autoplot.tbl_ts()",
24+
with = "ggtime::autoplot.tbl_ts()",
25+
details = "Graphics functions have been moved to the {ggtime} package. Please use `library(ggtime)` instead."
26+
)
2227
quo_vars <- enquo(.vars)
2328

2429
kv <- key_vars(object)
@@ -76,8 +81,13 @@ autoplot.tbl_ts <- function(object, .vars = NULL, ...){
7681

7782
#' @rdname autoplot.tbl_ts
7883
#' @importFrom ggplot2 ggplot aes geom_line guides guide_legend xlab
79-
#' @export
8084
autolayer.tbl_ts <- function(object, .vars = NULL, ...){
85+
lifecycle::deprecate_soft(
86+
when = "0.6.0",
87+
what = "autolayer.tbl_ts()",
88+
with = "ggtime::autolayer.tbl_ts()",
89+
details = "Graphics functions have been moved to the {ggtime} package. Please use `library(ggtime)` instead."
90+
)
8191
quo_vars <- enquo(.vars)
8292
kv <- key_vars(object)
8393
nk <- n_keys(object)
@@ -121,7 +131,6 @@ autolayer.tbl_ts <- function(object, .vars = NULL, ...){
121131
}
122132

123133
#' @importFrom ggplot2 fortify
124-
#' @export
125134
fortify.fbl_ts <- function(model, data = NULL, level = c(80, 95), ...){
126135
return(as_tibble(model))
127136
}
@@ -152,8 +161,14 @@ fortify.fbl_ts <- function(model, data = NULL, level = c(80, 95), ...){
152161
#' autoplot(aus_production)
153162
#'
154163
#' @importFrom ggplot2 facet_wrap
155-
#' @export
156164
autoplot.fbl_ts <- function(object, data = NULL, level = c(80, 95), show_gap = TRUE, ...){
165+
lifecycle::deprecate_soft(
166+
when = "0.6.0",
167+
what = "autoplot.fbl_ts()",
168+
with = "ggtime::autoplot.fbl_ts()",
169+
details = "Graphics functions have been moved to the {ggtime} package. Please use `library(ggtime)` instead."
170+
)
171+
157172
fc_resp <- response_vars(object)
158173
fc_key <- setdiff(key_vars(object), ".model")
159174
common_models <- duplicated(key_data(object)[[".model"]] %||% rep(TRUE, NROW(key_data(object))))
@@ -219,10 +234,14 @@ autoplot.fbl_ts <- function(object, data = NULL, level = c(80, 95), show_gap = T
219234
#' aus_production %>%
220235
#' autoplot(Beer) +
221236
#' autolayer(fc)
222-
#'
223-
#' @export
224237
autolayer.fbl_ts <- function(object, data = NULL, level = c(80, 95),
225238
point_forecast = list(mean = mean), show_gap = TRUE, ...){
239+
lifecycle::deprecate_soft(
240+
when = "0.6.0",
241+
what = "autolayer.fbl_ts()",
242+
with = "ggtime::autolayer.fbl_ts()",
243+
details = "Graphics functions have been moved to the {ggtime} package. Please use `library(ggtime)` instead."
244+
)
226245
build_fbl_layer(object = object, data = data, level = level,
227246
point_forecast = point_forecast, show_gap = show_gap, ...)
228247

@@ -470,9 +489,14 @@ build_fbl_layer <- function(object, data = NULL, level = c(80, 95),
470489
#' autoplot()
471490
#'
472491
#' @importFrom ggplot2 ggplot geom_line geom_rect facet_grid vars ylab labs after_stat
473-
#' @export
474492
autoplot.dcmp_ts <- function(object, .vars = NULL, scale_bars = TRUE,
475493
level = c(80, 95), ...){
494+
lifecycle::deprecate_soft(
495+
when = "0.6.0",
496+
what = "autoplot.dcmp_ts()",
497+
with = "ggtime::autoplot.dcmp_ts()",
498+
details = "Graphics functions have been moved to the {ggtime} package. Please use `library(ggtime)` instead."
499+
)
476500
method <- object%@%"method"
477501
idx <- index(object)
478502
keys <- key(object)

R/zzz.R

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,31 @@ register_s3_method <- function(pkg, generic, class, fun = NULL) {
4545
}
4646
)
4747
}
48+
49+
.onAttach <- function(...) {
50+
ggtime_version <- package_version(as.character(packageDescription("ggtime", fields = "Version")))
51+
if (!is.na(ggtime_version)) {
52+
ggtime_ns <- getNamespace("ggtime")
53+
54+
register_s3_method("ggplot2", "autoplot", "tbl_ts", getS3method("autoplot", "tbl_ts", envir = ggtime_ns))
55+
register_s3_method("ggplot2", "autolayer", "tbl_ts", getS3method("autolayer", "tbl_ts", envir = ggtime_ns))
56+
register_s3_method("ggplot2", "autoplot", "dcmp_ts", getS3method("autoplot", "dcmp_ts", envir = ggtime_ns))
57+
if (ggtime_version >= "0.2.0") {
58+
register_s3_method("ggplot2", "autoplot", "fbl_ts", getS3method("autoplot", "fbl_ts", envir = ggtime_ns))
59+
register_s3_method("ggplot2", "autolayer", "fbl_ts", getS3method("autolayer", "fbl_ts", envir = ggtime_ns))
60+
register_s3_method("ggplot2", "fortify", "tbl_ts", getS3method("fortify", "fbl_ts", envir = ggtime_ns))
61+
} else {
62+
register_s3_method("ggplot2", "autoplot", "fbl_ts", autoplot.fbl_ts)
63+
register_s3_method("ggplot2", "autolayer", "fbl_ts", autolayer.fbl_ts)
64+
register_s3_method("ggplot2", "fortify", "tbl_ts", fortify.fbl_ts)
65+
}
66+
} else {
67+
register_s3_method("ggplot2", "autoplot", "fbl_ts", autoplot.fbl_ts)
68+
register_s3_method("ggplot2", "autoplot", "tbl_ts", autoplot.tbl_ts)
69+
register_s3_method("ggplot2", "autoplot", "dcmp_ts", autoplot.dcmp_ts)
70+
register_s3_method("ggplot2", "autolayer", "fbl_ts", autolayer.fbl_ts)
71+
register_s3_method("ggplot2", "autolayer", "tbl_ts", autolayer.fbl_ts)
72+
register_s3_method("ggplot2", "fortify", "tbl_ts", fortify.fbl_ts)
73+
}
74+
}
4875
# nocov end

_pkgdown.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,10 @@ reference:
130130
- new_transformation
131131
- title: Graphics
132132
desc: >
133-
Some `autoplot()` and `autolayer()` methods are defined for classes commonly used within fabletools.
134-
contents:
135-
- autoplot.tbl_ts
136-
- autolayer.tbl_ts
137-
- autoplot.fbl_ts
138-
- autolayer.fbl_ts
139-
- autoplot.dcmp_ts
133+
Graphics capabilities in feasts have moved to the [ggtime](https://pkg.mitchelloharawild.com/ggtime) package.
134+
135+
Please use `library(ggtime)` in your code in order to continue using the `autoplot()` and `autolayer()` functions previously provided by this package.
136+
140137
- title: Extension package helpers
141138
desc: >
142139
Functions provided to help develop extension packages.

man/aggregate_index.Rd

Lines changed: 2 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)