From 7250bf21bee82bc261f5d5f22db56b3ce9f4f82d Mon Sep 17 00:00:00 2001 From: Marius Appel Date: Wed, 31 Mar 2021 13:41:42 +0200 Subject: [PATCH 1/3] enable fast options by default --- DESCRIPTION | 6 +++--- R/zzz.R | 50 +++++++++++++++++++++-------------------------- man/setoptions.Rd | 21 +++++++++----------- 3 files changed, 34 insertions(+), 43 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index d74d455..a827826 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -24,11 +24,11 @@ Description: This package integrates the decomposition of time series into without interpolation. Furthermore now different models can be used to fit the time series data and detect structural changes (breaks). Depends: - R (>= 3.0.0) + R (>= 3.0.0), + strucchangeRcpp Imports: graphics, stats, - strucchange, zoo, forecast, sp, @@ -43,4 +43,4 @@ URL: http://bfast.R-Forge.R-project.org/ LazyLoad: yes LazyData: yes LinkingTo: Rcpp -RoxygenNote: 7.1.0 +RoxygenNote: 7.1.1 diff --git a/R/zzz.R b/R/zzz.R index e812207..d62a357 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -1,9 +1,9 @@ .onLoad <- function(libname, pkgname) { op <- options() op.bfast <- list( - bfast.prefer_matrix_methods = FALSE, - bfast.use_bfastts_modifications = FALSE, - strucchange.use_armadillo=FALSE + bfast.prefer_matrix_methods = TRUE, + bfast.use_bfastts_modifications = TRUE, + strucchange.use_armadillo=TRUE ) toset <- !(names(op.bfast) %in% names(op)) if(any(toset)) options(op.bfast[toset]) @@ -13,16 +13,14 @@ #' Set package options with regard to computation times #' -#' These functions set options of the bfast and strucchange package to enable -#' faster computations. The fast options should return equal results but -#' require a compatible version of the \code{strucchange} package with -#' matrix-based functions. Notice that only some functions of the \code{bfast} -#' package make use of these options. +#' These functions set options of the bfast and strucchangeRcpp packages to enable +#' faster computations. By default (\code{set_default_options}), these optimizations are +#' enabled. Notice that only some functions of the \code{bfast} +#' package make use of these options. \code{set_fastt_options} is an alias for \code{set_default_options}. #' #' @name setoptions -#' @aliases set_fast_options set_default_options +#' @aliases set_default_options set_fallback_options set_fast_options #' @return A list of modified options and their new values. -#' @author Marius Appel #' @examples #' #' @@ -30,29 +28,25 @@ #' library(zoo) #' NDVIa <- as.ts(zoo(som$NDVI.a, som$Time)) #' -#' set_fast_options() +#' set_default_options() #' system.time(replicate(100, bfastmonitor(NDVIa, start = c(2010, 13)))) #' -#' set_default_options() +#' set_fallback_options() #' system.time(replicate(100, bfastmonitor(NDVIa, start = c(2010, 13)))) #' -#' @export set_fast_options set_default_options -set_fast_options <- function() { - if (!requireNamespace("strucchangeRcpp", quietly = TRUE)) { - warning("package strucchangeRcpp required for enabling fast options; using default implementation of strucchange") - } - else { - return(options(strucchange.use_armadillo=TRUE, - bfast.prefer_matrix_methods=TRUE, - bfast.use_bfastts_modifications=TRUE)) - } +#' @export set_fast_options set_default_options set_fallback_options +set_default_options <- function() { + return(options(strucchange.use_armadillo=TRUE, + bfast.prefer_matrix_methods=TRUE, + bfast.use_bfastts_modifications=TRUE)) } +set_fast_options <- function() { + set_default_options() +} -set_default_options <- function() { - if (requireNamespace("strucchangeRcpp", quietly = TRUE)) { - return(options(strucchange.use_armadillo=FALSE, - bfast.prefer_matrix_methods=FALSE, - bfast.use_bfastts_modifications=FALSE)) - } +set_fallback_options <- function() { + return(options(strucchange.use_armadillo=FALSE, + bfast.prefer_matrix_methods=FALSE, + bfast.use_bfastts_modifications=FALSE)) } diff --git a/man/setoptions.Rd b/man/setoptions.Rd index edd13f4..3f60f0a 100644 --- a/man/setoptions.Rd +++ b/man/setoptions.Rd @@ -2,21 +2,21 @@ % Please edit documentation in R/zzz.R \name{setoptions} \alias{setoptions} -\alias{set_fast_options} \alias{set_default_options} +\alias{set_fallback_options} +\alias{set_fast_options} \title{Set package options with regard to computation times} \usage{ -set_fast_options() +set_default_options() } \value{ A list of modified options and their new values. } \description{ -These functions set options of the bfast and strucchange package to enable -faster computations. The fast options should return equal results but -require a compatible version of the \code{strucchange} package with -matrix-based functions. Notice that only some functions of the \code{bfast} -package make use of these options. +These functions set options of the bfast and strucchangeRcpp packages to enable +faster computations. By default (\code{set_default_options}), these optimizations are +enabled. Notice that only some functions of the \code{bfast} +package make use of these options. \code{set_fastt_options} is an alias for \code{set_default_options}. } \examples{ @@ -25,13 +25,10 @@ package make use of these options. library(zoo) NDVIa <- as.ts(zoo(som$NDVI.a, som$Time)) -set_fast_options() +set_default_options() system.time(replicate(100, bfastmonitor(NDVIa, start = c(2010, 13)))) -set_default_options() +set_fallback_options() system.time(replicate(100, bfastmonitor(NDVIa, start = c(2010, 13)))) } -\author{ -Marius Appel -} From 657dc10e32b760779db3beeeb9b943335ea6d3fe Mon Sep 17 00:00:00 2001 From: Marius Appel Date: Wed, 31 Mar 2021 14:38:20 +0200 Subject: [PATCH 2/3] add set_fallback_options to NAMESPACE --- NAMESPACE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NAMESPACE b/NAMESPACE index b97a00b..6ae81f0 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -28,11 +28,11 @@ export(bfastpp) export(bfastts) export(create16dayts) export(set_default_options) +export(set_fallback_options) export(set_fast_options) import(forecast) import(raster) import(sp) -import(strucchange) import(zoo) importFrom(Rcpp,evalCpp) useDynLib(bfast) From ddbb2db80d6bca954f92a073f4696dabc9b0cc28 Mon Sep 17 00:00:00 2001 From: Marius Appel Date: Tue, 6 Apr 2021 12:46:59 +0200 Subject: [PATCH 3/3] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Dainius Masiliƫnas --- R/zzz.R | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/R/zzz.R b/R/zzz.R index b54b74f..e8065e6 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -17,7 +17,7 @@ #' These functions set options of the bfast and strucchangeRcpp packages to enable #' faster computations. By default (\code{set_default_options}), these optimizations are #' enabled. Notice that only some functions of the \code{bfast} -#' package make use of these options. \code{set_fastt_options} is an alias for \code{set_default_options}. +#' package make use of these options. \code{set_fast_options} is an alias for \code{set_default_options}. #' #' @name setoptions #' @aliases set_default_options set_fallback_options set_fast_options @@ -42,9 +42,7 @@ set_default_options <- function() { bfast.use_bfastts_modifications=TRUE)) } -set_fast_options <- function() { - set_default_options() -} +set_fast_options <- set_default_options set_fallback_options <- function() { return(options(strucchange.use_armadillo=FALSE,