
Save a data frame to an XLSX workbook split by a grouping column
Source:R/check-report-xlsx.R
ks_save2xlsx_by.RdWrites data to an XLSX file, creating one worksheet per unique value
of split_col. Rows can be colour-highlighted based on the content of
a message column (e.g. the output of ks_check_rules collapsed
with ks_collapse_check_msgs) and optionally a status column.
Column labels (stored as "label" attributes) are written as a grey
italic row above the data headers when present.
Usage
ks_save2xlsx_by(
data,
file,
colors,
split_col = type,
msg_col = check_msgs,
na_to_empty = FALSE,
status_col = NULL,
status_colors = NULL
)Arguments
- data
A data frame.
- file
Character. Path to the output
.xlsxfile.- colors
Named character vector mapping message substrings to hex colour codes (e.g.
c("Error" = "#FFCCCC", "OK" = "#CCFFCC")). Values with or without leading"#"are accepted.- split_col
<tidy-select>Bare name of the column used to split data into worksheets. Defaulttype.- msg_col
<tidy-select>Bare name of the column that contains check messages used for row colouring. Defaultcheck_msgs.- na_to_empty
Logical. If
TRUE, replaceNAand"#N/A"in character columns with empty strings. DefaultFALSE.- status_col
<tidy-select>Optional bare name of a status column (e.g. fromks_compare_check_state) used for a secondary layer of row colouring that overridescolors. PassNULLto disable. DefaultNULL.- status_colors
Named character vector mapping status values to hex colour codes. Used only when
status_colis notNULL. Values with or without leading"#"are accepted.
Examples
if (FALSE) { # \dontrun{
ks_save2xlsx_by(
results,
file = "output/checks.xlsx",
colors = c("Error" = "#FFCCCC", "Warning" = "#FFFF99"),
split_col = type,
msg_col = check_msgs
)
} # }