check_threshold: Internal Function: Perform an action (e.g., warning, error)...

Description Usage Arguments See Also Examples

View source: R/dashboard.R

Description

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

Usage

1
2
3
4
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

1
2
3
4
5
6
7
8
9
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)

# this will produce an error
# check_threshold(x, 5, action = function(...) stop(..., call. = FALSE))

southwick-associates/salic documentation built on Nov. 5, 2019, 9:13 a.m.