diff --git a/DESCRIPTION b/DESCRIPTION index 374ce18..baa7230 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -49,7 +49,7 @@ License: GPL-3 URL: http://feasts.tidyverts.org/, https://github.com/tidyverts/feasts/ BugReports: https://github.com/tidyverts/feasts/issues Encoding: UTF-8 -RoxygenNote: 7.3.2.9000 +RoxygenNote: 7.3.3 Roxygen: list(markdown = TRUE, roclets=c('rd', 'collate', 'namespace')) Language: en-GB RdMacros: lifecycle diff --git a/R/features.R b/R/features.R index e8db652..1952b76 100644 --- a/R/features.R +++ b/R/features.R @@ -137,7 +137,7 @@ feat_stl <- function(x, .period, s.window = 11, ...){ #' @rdname unitroot #' @export unitroot_kpss <- function(x, type = c("mu", "tau"), lags = c("short", "long", "nil"), ...) { - require_package("urca") + check_installed("urca") result <- urca::ur.kpss(x, type = type, lags = lags, ...) pval <- stats::approx(result@cval[1,], as.numeric(sub("pct", "", colnames(result@cval)))/100, xout=result@teststat[1], rule=2)$y c(kpss_stat = result@teststat, kpss_pvalue = pval) @@ -151,7 +151,7 @@ unitroot_kpss <- function(x, type = c("mu", "tau"), lags = c("short", "long", "n #' @export unitroot_pp <- function(x, type = c("Z-tau", "Z-alpha"), model = c("constant", "trend"), lags = c("short", "long"), ...) { - require_package("urca") + check_installed("urca") result <- urca::ur.pp(x, type = match.arg(type), model = match.arg(model), lags = match.arg(lags), ...) pval <- stats::approx(result@cval[1,], as.numeric(sub("pct", "", colnames(result@cval)))/100, xout=result@teststat[1], rule=2)$y @@ -247,7 +247,7 @@ unitroot_nsdiffs <- function(x, alpha = 0.05, unitroot_fn = ~ feat_stl(.,.period #' #' @export cointegration_johansen <- function(x, ...) { - require_package("urca") + check_installed("urca") result <- urca::ca.jo(x, ...) pct <- as.numeric(sub("pct", "", colnames(result@cval)))/100 @@ -273,7 +273,7 @@ cointegration_johansen <- function(x, ...) { #' #' @export cointegration_phillips_ouliaris <- function(x, ...) { - require_package("urca") + check_installed("urca") result <- urca::ca.po(x, ...) pval <- stats::approx(result@cval[1,], as.numeric(sub("pct", "", colnames(result@cval)))/100, xout=result@teststat[1], rule=2)$y c(phillips_ouliaris_stat = result@teststat, phillips_ouliaris_pvalue = pval) @@ -315,7 +315,7 @@ n_flat_spots <- function(x) { #' #' @export coef_hurst <- function(x) { - require_package("fracdiff") + check_installed("fracdiff") # Hurst=d+0.5 where d is fractional difference. return(c(coef_hurst = suppressWarnings(fracdiff::fracdiff(na.contiguous(x), 0, 0)[["d"]] + 0.5))) } diff --git a/R/graphics.R b/R/graphics.R index 5b13419..5405b99 100644 --- a/R/graphics.R +++ b/R/graphics.R @@ -371,7 +371,7 @@ gg_season <- function(data, y = NULL, period = NULL, facet_period = NULL, if(labels != "none"){ labeller <- if(labels_repel) { - require_package("ggrepel") + check_installed("ggrepel") function(...) ggrepel::geom_text_repel(..., direction = "y", segment.colour = NA) } else { ggplot2::geom_text @@ -652,7 +652,7 @@ gg_tsdisplay <- function(data, y = NULL, plot_type = c("auto", "partial", "seaso if(n_keys(data) > 1){ abort("The data provided to contains more than one time series. Please filter a single time series to use `gg_tsdisplay()`") } - require_package("grid") + check_installed("grid") y <- guess_plot_var(data, !!enquo(y)) @@ -744,14 +744,12 @@ gg_tsdisplay <- function(data, y = NULL, plot_type = c("auto", "partial", "seaso #' and practice}, 3rd edition, OTexts: Melbourne, Australia. #' \url{https://OTexts.com/fpp3/} #' -#' @examples -#' if (requireNamespace("fable", quietly = TRUE)) { +#' @examplesIf rlang::is_installed("fable") #' library(fable) #' #' tsibbledata::aus_production %>% #' model(ETS(Beer)) %>% #' gg_tsresiduals() -#' } #' #' @importFrom ggplot2 ggplot aes geom_point geom_histogram ylim #' @importFrom stats na.exclude complete.cases diff --git a/R/seats.R b/R/seats.R index 70e6fac..0f358db 100644 --- a/R/seats.R +++ b/R/seats.R @@ -17,7 +17,7 @@ specials_seats <- fabletools::new_specials( ) train_seats <- function(.data, formula, specials, x11, x11.mode, ...){ - require_package("seasonal") + check_installed("seasonal") stopifnot(is_tsibble(.data)) if(!missing(x11) || !missing(x11.mode)){ diff --git a/R/utils.R b/R/utils.R index 52f37ab..64c0e4b 100644 --- a/R/utils.R +++ b/R/utils.R @@ -6,14 +6,6 @@ add_class <- function(x, new_class){ if (is.null(x)) y else x } -require_package <- function(pkg){ - if(!requireNamespace(pkg, quietly = TRUE)){ - abort( - sprintf('The `%s` package must be installed to use this functionality. It can be installed with install.packages("%s")', pkg, pkg) - ) - } -} - `%empty%` <- function(x, y) { if (length(x) == 0) y else x } diff --git a/R/x11.R b/R/x11.R index 94bcd48..08719e2 100644 --- a/R/x11.R +++ b/R/x11.R @@ -17,7 +17,7 @@ specials_X11 <- fabletools::new_specials( ) train_X11 <- function(.data, formula, specials, type, ...){ - require_package("seasonal") + check_installed("seasonal") stopifnot(is_tsibble(.data)) if(length(specials$season) != 1){ diff --git a/R/x13arimaseats.R b/R/x13arimaseats.R index 953c46c..9f625ec 100644 --- a/R/x13arimaseats.R +++ b/R/x13arimaseats.R @@ -32,7 +32,7 @@ specials_x13arimaseats <- fabletools::new_specials( train_x13arimaseats <- function(.data, formula, specials, ..., defaults, na.action = seasonal::na.x13){ - require_package("seasonal") + check_installed("seasonal") stopifnot(is_tsibble(.data)) series_name <- measured_vars(.data) diff --git a/man/gg_tsresiduals.Rd b/man/gg_tsresiduals.Rd index 1705195..0a222ac 100644 --- a/man/gg_tsresiduals.Rd +++ b/man/gg_tsresiduals.Rd @@ -30,14 +30,13 @@ A list of ggplot objects showing a useful plots of a time series model's residua Plots the residuals using a time series plot, ACF and histogram. } \examples{ -if (requireNamespace("fable", quietly = TRUE)) { +\dontshow{if (rlang::is_installed("fable")) withAutoprint(\{ # examplesIf} library(fable) tsibbledata::aus_production \%>\% model(ETS(Beer)) \%>\% gg_tsresiduals() -} - +\dontshow{\}) # examplesIf} } \references{ Hyndman and Athanasopoulos (2019) \emph{Forecasting: principles