Skip to content

Commit fdbb013

Browse files
Move ggtime method registration from .onAttach to .onLoad
1 parent b5a5ae0 commit fdbb013

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

R/zzz.R

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,37 @@
1212

1313
register_s3_method("ggplot2", "scale_type", "agg_vec")
1414

15+
# fabletools -> ggtime method migration
16+
ggtime_version <- package_version(as.character(
17+
suppressWarnings(
18+
utils::packageDescription("ggtime", fields = "Version")
19+
)
20+
))
21+
if (!is.na(ggtime_version)) {
22+
ggtime_ns <- getNamespace("ggtime")
23+
24+
register_s3_method("ggplot2", "autoplot", "tbl_ts", utils::getS3method("autoplot", "tbl_ts", envir = ggtime_ns))
25+
register_s3_method("ggplot2", "autolayer", "tbl_ts", utils::getS3method("autolayer", "tbl_ts", envir = ggtime_ns))
26+
register_s3_method("ggplot2", "autoplot", "dcmp_ts", utils::getS3method("autoplot", "dcmp_ts", envir = ggtime_ns))
27+
if (ggtime_version >= "0.2.0") {
28+
register_s3_method("ggplot2", "autoplot", "fbl_ts", utils::getS3method("autoplot", "fbl_ts", envir = ggtime_ns))
29+
register_s3_method("ggplot2", "autolayer", "fbl_ts", utils::getS3method("autolayer", "fbl_ts", envir = ggtime_ns))
30+
register_s3_method("ggplot2", "fortify", "tbl_ts", utils::getS3method("fortify", "fbl_ts", envir = ggtime_ns))
31+
} else {
32+
register_s3_method("ggplot2", "autoplot", "fbl_ts", autoplot.fbl_ts)
33+
register_s3_method("ggplot2", "autolayer", "fbl_ts", autolayer.fbl_ts)
34+
register_s3_method("ggplot2", "fortify", "tbl_ts", fortify.fbl_ts)
35+
}
36+
} else {
37+
register_s3_method("ggplot2", "autoplot", "fbl_ts", autoplot.fbl_ts)
38+
register_s3_method("ggplot2", "autoplot", "tbl_ts", autoplot.tbl_ts)
39+
register_s3_method("ggplot2", "autoplot", "dcmp_ts", autoplot.dcmp_ts)
40+
register_s3_method("ggplot2", "autolayer", "fbl_ts", autolayer.fbl_ts)
41+
register_s3_method("ggplot2", "autolayer", "tbl_ts", autolayer.fbl_ts)
42+
register_s3_method("ggplot2", "fortify", "tbl_ts", fortify.fbl_ts)
43+
}
44+
45+
1546
op <- options()
1647
op.fable <- list(
1748
fable.show_progress = TRUE
@@ -45,35 +76,4 @@ register_s3_method <- function(pkg, generic, class, fun = NULL) {
4576
}
4677
)
4778
}
48-
49-
.onAttach <- function(...) {
50-
ggtime_version <- package_version(as.character(
51-
suppressWarnings(
52-
utils::packageDescription("ggtime", fields = "Version")
53-
)
54-
))
55-
if (!is.na(ggtime_version)) {
56-
ggtime_ns <- getNamespace("ggtime")
57-
58-
register_s3_method("ggplot2", "autoplot", "tbl_ts", utils::getS3method("autoplot", "tbl_ts", envir = ggtime_ns))
59-
register_s3_method("ggplot2", "autolayer", "tbl_ts", utils::getS3method("autolayer", "tbl_ts", envir = ggtime_ns))
60-
register_s3_method("ggplot2", "autoplot", "dcmp_ts", utils::getS3method("autoplot", "dcmp_ts", envir = ggtime_ns))
61-
if (ggtime_version >= "0.2.0") {
62-
register_s3_method("ggplot2", "autoplot", "fbl_ts", utils::getS3method("autoplot", "fbl_ts", envir = ggtime_ns))
63-
register_s3_method("ggplot2", "autolayer", "fbl_ts", utils::getS3method("autolayer", "fbl_ts", envir = ggtime_ns))
64-
register_s3_method("ggplot2", "fortify", "tbl_ts", utils::getS3method("fortify", "fbl_ts", envir = ggtime_ns))
65-
} else {
66-
register_s3_method("ggplot2", "autoplot", "fbl_ts", autoplot.fbl_ts)
67-
register_s3_method("ggplot2", "autolayer", "fbl_ts", autolayer.fbl_ts)
68-
register_s3_method("ggplot2", "fortify", "tbl_ts", fortify.fbl_ts)
69-
}
70-
} else {
71-
register_s3_method("ggplot2", "autoplot", "fbl_ts", autoplot.fbl_ts)
72-
register_s3_method("ggplot2", "autoplot", "tbl_ts", autoplot.tbl_ts)
73-
register_s3_method("ggplot2", "autoplot", "dcmp_ts", autoplot.dcmp_ts)
74-
register_s3_method("ggplot2", "autolayer", "fbl_ts", autolayer.fbl_ts)
75-
register_s3_method("ggplot2", "autolayer", "tbl_ts", autolayer.fbl_ts)
76-
register_s3_method("ggplot2", "fortify", "tbl_ts", fortify.fbl_ts)
77-
}
78-
}
7979
# nocov end

0 commit comments

Comments
 (0)