Nothing
#' Diagnostic codes
#'
#' Registry of the stable diagnostic codes used by the validation functions.
#' The first letter after `SM-` gives the severity: `E` error, `W` warning, `I` info.
#' Codes `SM-x0xx` concern the specification files in `inst/spec`,
#' codes `SM-x2xx` and `SM-x3xx` the checks of management data in [check_management_df()],
#' codes `SM-x4xx` the validation of management JSON in [management_df_from_json()].
#'
#' @md
#' @noRd
diagnostic_codes <- data.frame(
code = c("SM-E001", "SM-E002", "SM-E003", "SM-E004", "SM-E005", "SM-E006", "SM-E007", "SM-E008", "SM-E009",
"SM-W002", "SM-W003", "SM-W004",
"SM-I001",
"SM-W201", "SM-W202", "SM-W203", "SM-W204", "SM-W205", "SM-W206", "SM-W207",
"SM-W208", "SM-W209", "SM-W210", "SM-W211", "SM-W212", "SM-W213", "SM-W214",
"SM-W215", "SM-W216", "SM-W217",
"SM-I301",
"SM-E401", "SM-E402", "SM-E403", "SM-E404", "SM-E405", "SM-E406", "SM-E407", "SM-E408"),
title = c("specification file missing or not readable",
"specification does not follow its schema",
"duplicated identifier",
"ambiguous alias",
"reference to an unknown identifier",
"unknown source key",
"seed mixture components do not add up",
"inconsistent species information",
"specification file not listed in the manifest",
"description is a draft and needs review",
"definition is not used",
"parameters missing for a calculation",
"schema validation skipped",
"dates are not chronological",
"year does not match the date",
"device is missing",
"unknown category",
"unknown combination of category and operation",
"crop is harvested more than once",
"organic amendment not in the lookup table",
"tillage or sowing device without STIR value",
"crop not in C_input_crops_LUT",
"crop not in plant_cover_LUT",
"unexpected order of operations",
"high application rate of organic amendment",
"high application rate of mineral N",
"unexpected depth of tillage operation",
"mineral fertilizer without N content",
"mineral fertilizer entered twice",
"date is not of class Date",
"product not in the catalogue",
"management JSON has an invalid structure",
"record is not an object or has an unknown attribute",
"value has the wrong type",
"date does not exist",
"required value is missing",
"unknown vocabulary",
"combination of category, operation, device and unit is not allowed",
"management JSON does not follow the JSON Schema"),
stringsAsFactors = FALSE
)
#' Create diagnostics for management data
#'
#' Returns diagnostics of [check_management_df()] as a data frame with one row
#' per affected record (`row` refers to the rows of the input data).
#'
#' @param code diagnostic code from `diagnostic_codes`
#' @param message description of the finding
#' @param row row numbers of the affected records, NA if the finding concerns no specific row
#' @param attribute affected attribute (column)
#'
#' @md
#' @noRd
management_diagnostic <- function(code, message, row = NA_integer_, attribute = NA_character_) {
d <- diagnostic(code, message)
if (length(row) == 0) row <- NA_integer_
data.frame(severity = d$severity, code = code, row = as.integer(row), attribute = attribute,
message = message, stringsAsFactors = FALSE)
}
#' Create diagnostics
#'
#' Returns diagnostics as a data frame with one row per finding.
#'
#' @param code diagnostic code from `diagnostic_codes`
#' @param message description of the finding
#' @param file specification file
#' @param entry identifier of the affected entry
#' @param attribute affected attribute or JSON path
#'
#' @md
#' @noRd
diagnostic <- function(code, message, file = NA_character_, entry = NA_character_, attribute = NA_character_) {
if (!all(code %in% diagnostic_codes$code)) {
stop("Unknown diagnostic code: ", paste(setdiff(code, diagnostic_codes$code), collapse = ", "))
}
severity <- c(E = "error", W = "warning", I = "info")[substr(code, 4, 4)]
data.frame(severity = unname(severity), code = code, file = file, entry = entry,
attribute = attribute, message = message, stringsAsFactors = FALSE)
}
#' Empty diagnostics table
#' @noRd
no_diagnostics <- function() {
diagnostic("SM-I001", "")[0, ]
}
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.