The action is only triggered if any values in df[[test_variable]] exceed test_threshold. Intended for use in calculating dashboard metrics.

check_threshold(df, test_threshold, test_variable = "pct_change",
  action = function(...) warning(..., call. = FALSE),
  msg = paste("Threshold of", test_threshold, "for", test_variable,
  "exceeded:"))

Arguments

df

data frame: table containing statistic to check

test_threshold

numeric: if exceeded, while produce warning

test_variable

character: Name of variable in df that contains the test statistic

action

function: function call to perform if threshold is exceeded (intended to be warning or stop).

msg

character: message to be printed in action

See also

Other dashboard functions: est_churn, est_part, format_result, scaleup_part

Examples

library(dplyr) # produce warnings x <- data.frame(tot = "All", year = 2008:2018, part = rnorm(11, 1000, sd = 100)) x <- mutate(x, pct_change = (part - lag(part)) / lag(part) * 100) check_threshold(x, 5)
#> Warning: Threshold of 5 for pct_change exceeded: #> tot year part pct_change #> 1 All 2009 1025.5317 19.248476 #> 2 All 2010 756.2736 -26.255460 #> 3 All 2011 999.4429 32.153604 #> 4 All 2012 1062.1553 6.274736 #> 5 All 2014 817.8182 -26.642623 #> 6 All 2015 975.2675 19.252351
# this will produce an error # check_threshold(x, 5, action = function(...) stop(..., call. = FALSE))