Skip to content

Commit c100692

Browse files
added check for nonmapped values that could create error between baseline and hypo
1 parent ff9dd89 commit c100692

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

R/rateParser.R

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,21 @@ eval_map <- function(df, rate_part){
254254
stopif( check, paste0("One of the fields (", rate_part$depends_on, ") is not present.",
255255
" It can be defined either in the data or in the rate file.") )
256256

257-
# Appened together each element in the dependency columns
257+
# Append together each element in the dependency columns
258258
keys <- do.call(paste, c(df[rate_part$depends_on], sep = "|"))
259259

260260
# Get the value mapping, and flatten together in the case of tiers
261261
pricemap <- rate_part$values
262262
pricemap <- collapse_tiers(pricemap)
263+
results <- unname(unlist(pricemap)[keys])
263264

264-
return( unname(unlist(pricemap)[keys]) )
265+
nonmaps <- unique(keys[is.na(results)])
266+
valid_nas <- c("", "NA")
267+
check <- any(!(nonmaps %in% valid_nas))
268+
stopif(check, paste0("The following map keys are missing from the OWRS file: (",
269+
paste(nonmaps[!(nonmaps %in% valid_nas)], collapse = ", "), ")") )
270+
271+
return( results )
265272
}
266273

267274
#' Check whether a rate part is a map.

0 commit comments

Comments
 (0)