Write the tables of run_monitor() as one Excel workbook, with a colour scale on every wide sheet, or as CSV files.

write_monitor_tables(
  x,
  path,
  format = c("xlsx", "csv"),
  file = "monitor",
  verbose = 1
)

Arguments

x

Result of run_monitor().

path

Folder to write to (created if needed).

format

"xlsx" (default; needs the openxlsx package) or "csv".

file

File name without extension (xlsx) or prefix of the file names (csv). Default "monitor".

verbose

0 (silent) or 1 (summary, default).

Value

Invisibly, the path(s) of the written file(s).

Sheets

The workbook has the long tables Alerts, Stations, Houses, Pigs (the pig_summary of run_monitor()) and Pig days, and wide sheets (see wide_table()) with a colour scale from red (a possible problem) over yellow to green:

SheetValuesRed for
Visitsvisits per station and daylow
Unidentified pctunidentified visits, %high
Feed kgfeed intake per stationlow
Feed per pig kgfeed intake per piglow
Occupation hoccupation timelow
Weight outliers pctbody weight outliers, %high
House feed per pig kgfeed intake per pig and houselow
House weight kgmean body weight per house(blue scale)
Pig feed kgfeed intake per pig and daylow
Hours visits, Hours feed kgper hour of the last day(blue scale)

The CSV files are the long tables <file>_alerts.csv, <file>_stations.csv, <file>_houses.csv, <file>_pigs.csv, <file>_pig_days.csv and <file>_hours.csv, written with a byte order mark so that Excel opens them in UTF-8.

Examples

mon <- run_monitor(tidypptsda::nedap, verbose = 0)
dir <- file.path(tempdir(), "monitor_tables")
write_monitor_tables(mon, dir, format = "csv")
#> ✔ Wrote 6 CSV files to /tmp/RtmpBRLQC3/monitor_tables
if (requireNamespace("openxlsx", quietly = TRUE)) {
  write_monitor_tables(mon, dir)
}
#> ✔ Wrote /tmp/RtmpBRLQC3/monitor_tables/monitor.xlsx (16 sheets)
unlink(dir, recursive = TRUE)
mon <- run_monitor(tidypptsda::nedap, verbose = 0)
dir <- file.path(tempdir(), "monitor_tables")
write_monitor_tables(mon, dir, format = "csv")
#> ✔ Wrote 6 CSV files to /tmp/RtmpBRLQC3/monitor_tables
unlink(dir, recursive = TRUE)