Dynamically generate a table containing alert results for an rmd chunk
Source:R/construct.R
bespoke_rmd_alert_results.Rd
Add mantis
alert results to an existing rmarkdown
report. The function
writes directly to the chunk using side-effects, so chunk options must
contain results = 'asis'
.
Arguments
- df
A data frame containing multiple time series in long format. See Details.
- inputspec
inputspec()
object specifying which columns in the supplieddf
represent the "timepoint", "item", and "value" for the time series. Any "tab" column specification will be ignored.- alert_rules
alert_rules()
object specifying conditions to test- filter_results
only return rows where the alert result is in this vector of values. Alert results can be "PASS", "FAIL", or "NA".
- timepoint_limits
Set start and end dates for time period to include. Defaults to min/max of
timepoint_col
- fill_with_zero
Logical. Replace any missing or
NA
values with 0? Useful whenvalue_col
is a record count- tab_name
Character string to appear on the tab label. If omitted or
NULL
, only the content (and not the parent tab) will be created.- tab_level
integer specifying the nesting level of the tab. If
tab_name
is specified, a value of 1 generates a tab at rmd level "##". Iftab_name
is not specified, this is ignored.
Examples
if (FALSE) { # \dontrun{
# put this inside a chunk in the rmd file,
# with chunk option `results = 'asis'`
mantis::bespoke_rmd_alert_results(
df = mantis::example_prescription_numbers,
inputspec = mantis::inputspec(
timepoint_col = "PrescriptionDate",
item_cols = c("Location", "Antibiotic"),
value_col = "NumberOfPrescriptions",
tab_col = "Location"
),
alert_rules = alert_rules(
alert_missing(extent_type = "any", extent_value = 1),
alert_equals(extent_type = "all", rule_value = 0)
),
filter_results = c("FAIL", "NA"),
fill_with_zero = FALSE,
tab_name = "Failed alerts",
tab_level = 1
)
} # }