Skip to content

Commit

Permalink
allow suppressing messages to console
Browse files Browse the repository at this point in the history
  • Loading branch information
cszang committed Dec 13, 2024
1 parent 4e09c2b commit 7e6b166
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 37 deletions.
10 changes: 6 additions & 4 deletions R/dcc.R
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@
##' @param sb \code{logical} flag indicating whether textual status
##' bar for moving case should be suppressed. Suppression is
##' recommended for e.g. Sweave files.
##' @param verbose \code{logical} flag indicating if informative messages should
##' be written to the console (default is `TRUE`).
##' @return 'dcc' returns an 'object' of class '"tc_dcc"'.
##'
##' The functions 'summary' and 'plot' are used to obtain and print
Expand Down Expand Up @@ -193,9 +195,7 @@
##' selection for the dependent bootstrap, Econometric Reviews
##' 23(1), 53-70.
##' @examples
##' \dontrun{
##' dc_resp <- dcc(muc_spruce, muc_clim)
##' }
##' @author Christian Zang; the original MATLAB code for exact
##' bootstrapping was written by Dave Meko
##' @import Rcpp
Expand All @@ -216,7 +216,8 @@ dcc <- function(chrono,
var_names = NULL,
ci = 0.05,
boot = "stationary",
sb = TRUE
sb = TRUE,
verbose = TRUE
)
{

Expand Down Expand Up @@ -253,7 +254,8 @@ dcc <- function(chrono,
## time span
truncated_input <- truncate_input(chrono, climate,
timespan = timespan, minmonth,
.dynamic)
.dynamic,
silent = !verbose)

if (dynamic != "static" & truncated_input$missing) {
stop("Missing data in proxy series, moving or evolving functions are not computed.\n")
Expand Down
6 changes: 4 additions & 2 deletions R/dlm.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ dlm <- function(chrono,
var_names = NULL,
param_names = NULL,
intercept = TRUE,
scale = FALSE) {
scale = FALSE,
verbose = TRUE) {

climate <- apply_var_names(as_tcclimate(climate), var_names)
selection <- unify_selection(selection)
Expand All @@ -115,7 +116,8 @@ dlm <- function(chrono,
## time span
truncated_input <- truncate_input(chrono, climate,
timespan = timespan, minmonth,
dynamic = "static")
dynamic = "static",
silent = !verbose)

climate_pmat <- make_pmat(truncated_input$climate, truncated_input$pad)

Expand Down
50 changes: 28 additions & 22 deletions R/gershunov.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
##' @param boot \code{logical} shall the individual correlations be
##' bootstrapped? (see details)
##' @param sb \code{logical} shall a status bar be drawn?
##' @param check_duration \code{logical} should the duration be checked before
##' running with individually boostrapped correlations? The default is `TRUE`,
##' set to `FALSE` to suppress interactive selections and messages to the
##' console.
##' @return a \code{data.frame} with p values for the testing the null
##' hypothesis that the low-frequency modulation of the
##' correlations of the variables with tree-growth can be
Expand All @@ -36,13 +40,13 @@
##' Monsoon rainfall relationship: Signal or noise? Journal of
##' Climate 14:2486-2492.
##' @examples
##' \dontrun{
##' \donttest{
##' dc_cor <- dcc(muc_spruce, muc_clim, 3:9, method = "cor", moving = TRUE)
##' g_test(dc_cor)
##' }
##' @keywords test
##' @export
g_test <- function(x, boot = FALSE, sb = TRUE) {
g_test <- function(x, boot = FALSE, sb = TRUE, check_duration = TRUE) {
if (!any(class(x) != "tc_dcc"))
stop("Please provide output of function `dcc`.")

Expand Down Expand Up @@ -80,26 +84,28 @@ g_test <- function(x, boot = FALSE, sb = TRUE) {

## if boot is TRUE, warn because of long calculation, and give the
## option to cancel
if (boot) {
cat("Checking duration...\n")
dur <- system.time({
tc_mfunc(x$truncated$tree, x$design,
method = "correlation",
start_last = .start_last,
win_size = .win_size,
win_offset = .win_offset,
boot = .boot,
sb = FALSE,
ci = 0.05)
})
dur1000 <- ceiling(dur[3] * niter / 60)
cat("Running this test with bootstrapping on the individual correlations enabled will take around", dur1000, "minutes.\n")
ans <- readline("Do you really want to run this? [Y/n]\n")
if (ans != "Y")
stop("Execution interrupted by user.")
cat("Ok then. Maybe time to grab a sandwich?\n")
} else {
cat("Performing test without bootstrapping individual correlations.\n")
if (check_duration) {
if (boot) {
cat("Checking duration...\n")
dur <- system.time({
tc_mfunc(x$truncated$tree, x$design,
method = "correlation",
start_last = .start_last,
win_size = .win_size,
win_offset = .win_offset,
boot = .boot,
sb = FALSE,
ci = 0.05)
})
dur1000 <- ceiling(dur[3] * niter / 60)
cat("Running this test with bootstrapping on the individual correlations enabled will take around", dur1000, "minutes.\n")
ans <- readline("Do you really want to run this? [Y/n]\n")
if (ans != "Y")
stop("Execution interrupted by user.")
cat("Ok then. Maybe time to grab a sandwich?\n")
} else {
cat("Performing test without bootstrapping individual correlations.\n")
}
}

## test tree-ring data and the columns of the design matrix for normality
Expand Down
8 changes: 6 additions & 2 deletions R/seascorr.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@
##'
##' @param secondary position \code{numeric} or name \code{character}
##' of secondary climate variable
##'
##' @param verbose \code{logical} flag indicating if informative messages should
##' be written to the console (default is `TRUE`).
##'
##' @return 'seascorr' returns an 'object' of class '"tc_seascorr"'.
##'
Expand Down Expand Up @@ -106,7 +109,7 @@
##' @export
seascorr <- function(chrono, climate, var_names = NULL, timespan =
NULL, complete = 9, season_lengths = c(1, 3, 6),
primary = 1, secondary = 2, ci = 0.05) {
primary = 1, secondary = 2, ci = 0.05, verbose = TRUE) {

## check input
if (!any(1:12 == complete))
Expand Down Expand Up @@ -189,7 +192,8 @@ seascorr <- function(chrono, climate, var_names = NULL, timespan =
truncated_input <- truncate_input(chrono, climate,
timespan = timespan,
minmonth = minmonth,
dynamic = "static")
dynamic = "static",
silent = !verbose)

m <- length(truncated_input$chrono)

Expand Down
8 changes: 5 additions & 3 deletions man/dcc.Rd

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

6 changes: 5 additions & 1 deletion man/dlm.Rd

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

9 changes: 7 additions & 2 deletions man/g_test.Rd

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

6 changes: 5 additions & 1 deletion man/seascorr.Rd

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

0 comments on commit 7e6b166

Please sign in to comment.