From 928ce19c71bd992270ff19f00cddc586328611c5 Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Fri, 6 Oct 2023 13:09:35 +0100 Subject: [PATCH] warn of behaviour change --- NAMESPACE | 1 + R/dist.R | 13 +++++++++++++ tests/testthat/setup.R | 5 +++++ 3 files changed, 19 insertions(+) diff --git a/NAMESPACE b/NAMESPACE index 658547ad0..b4aa2fae8 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -185,6 +185,7 @@ importFrom(purrr,transpose) importFrom(purrr,walk) importFrom(rlang,abort) importFrom(rlang,cnd_muffle) +importFrom(rlang,warn) importFrom(rstan,expose_stan_functions) importFrom(rstan,extract) importFrom(rstan,sampling) diff --git a/R/dist.R b/R/dist.R index bb4c9ed69..b97761b58 100644 --- a/R/dist.R +++ b/R/dist.R @@ -892,6 +892,7 @@ tune_inv_gamma <- function(lower = 2, upper = 21) { #' #' @author Sebastian Funk #' @author Sam Abbott +#' @importFrom rlang warn #' @export #' @examples #' # A fixed lognormal distribution with mean 5 and sd 1. @@ -905,6 +906,18 @@ tune_inv_gamma <- function(lower = 2, upper = 21) { dist_spec <- function(mean, sd = 0, mean_sd = 0, sd_sd = 0, distribution = c("lognormal", "gamma"), max, pmf = numeric(0), fixed = FALSE) { + ## deprecate previous behaviour + warn( + message = paste( + "The meaning of the 'max' argument has changed compared to", + "previous versions. It now indicates the maximum of a distribution", + "rather than the length of the probability mass function (including 0)", + "that it represented previously. To replicate previous behaviour reduce", + "max by 1.\nThis warning is displayed onc every 8 hours." + ), + .frequency = "regularly", + .frequency_id = "dist_spec_max" + ) ## check if parametric or nonparametric if (length(pmf) > 0 && !all( diff --git a/tests/testthat/setup.R b/tests/testthat/setup.R index 46c7a2e83..b10a5bffa 100644 --- a/tests/testthat/setup.R +++ b/tests/testthat/setup.R @@ -15,3 +15,8 @@ if (identical(Sys.getenv("NOT_CRAN"), "true")) { } withr::defer(future::plan("sequential"), teardown_env()) + +## process warning once as previous behaviour has been deprecated +empty <- suppressWarnings(dist_spec()) + +