-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
86 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
Type: Package | ||
Package: piamValidation | ||
Title: Validation Tools for PIK-PIAM | ||
Version: 0.2.11 | ||
Date: 2024-05-28 | ||
Version: 0.2.12 | ||
Date: 2024-05-29 | ||
Authors@R: | ||
c(person("Pascal", "Weigmann",, "[email protected]", role = c("aut", "cre")), | ||
person("Oliver", "Richters",, role = "aut")) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#' Check variable consistency | ||
#' | ||
#' Test whether unit of on row of config and data for this variable match. | ||
#' | ||
#' @importFrom piamInterfaces areUnitsIdentical | ||
#' @importFrom dplyr filter | ||
#' | ||
#' @param data scenario or reference data for one variable | ||
#' @param cfgRow one row of a config file containing the same variable as the | ||
#' data object | ||
#' | ||
checkUnits <- function(data, cfgRow) { | ||
# empty unit field in config means skipping the check | ||
if (is.na(cfgRow$unit)) { | ||
message("No unit given in config for ", cfgRow$variable, | ||
", skipping consistency check.\n") | ||
} else { | ||
# identify data type | ||
dataType <- | ||
if(cfgRow$ref_scenario %in% "historical") "reference" else "scenario" | ||
|
||
units <- as.character(unique(data$unit)) | ||
for (i in 1:length(units)) { | ||
if (!piamInterfaces::areUnitsIdentical(cfgRow$unit, units[i])) { | ||
warning(paste0( | ||
"Non-matching units in config and ", dataType," data found.\n", | ||
"variable: ", cfgRow$variable, "\n", | ||
"config unit: ", cfgRow$unit, "\n", | ||
dataType, " unit: ", units[i]), "\n") | ||
# in case of the presence of non-matching units: | ||
# filter data for correct unit as it might also available, if not this | ||
# will result in an empty data object being returned | ||
data <- filter(data, data$unit %in% cfgRow$unit) | ||
} | ||
} | ||
} | ||
return(data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters