Skip to content

Commit

Permalink
Merge pull request #81 from bfast2/set_options
Browse files Browse the repository at this point in the history
enable fast options by default
  • Loading branch information
GreatEmerald authored Apr 9, 2021
2 parents d9028bb + ddbb2db commit def30fe
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 41 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ BugReports: https://github.com/bfast2/bfast/issues
LazyLoad: yes
LazyData: yes
LinkingTo: Rcpp
RoxygenNote: 7.1.0
RoxygenNote: 7.1.1
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export(bfastpp)
export(bfastts)
export(create16dayts)
export(set_default_options)
export(set_fallback_options)
export(set_fast_options)
import(forecast)
import(stats)
Expand Down
49 changes: 21 additions & 28 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -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])
Expand All @@ -13,46 +13,39 @@

#' Set package options with regard to computation times
#'
#' These functions set options of the bfast and strucchangeRcpp package to enable
#' faster computations. The fast options should return equal results but
#' require the \code{strucchangeRcpp} package, which includes
#' 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_fast_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
#'
#'
#' # run bfastmonitor with different options and compare computation times
#' 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 <- 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))
}
21 changes: 9 additions & 12 deletions man/setoptions.Rd

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

0 comments on commit def30fe

Please sign in to comment.