-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathpriceIndicesIIASA.R
21 lines (21 loc) · 1.06 KB
/
priceIndicesIIASA.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#' Add Price|*|Index variables requested in iiasatemplate but missing in data,
#' if Price|* is present in data. Extracts reference year automatically from unit
#'
#' @md
#' @author Oliver Richters
#' @param mifdata file or data that can be converted into quitte object
#' @param iiasatemplate filename of xlsx or yaml file provided by IIASA
#' @param scenBase optional scenario name of baseline scenario used to calculate index
#' @export
priceIndicesIIASA <- function(mifdata, iiasatemplate, scenBase = NULL) {
# Add missing Price|*|Index variables if Price|* is present in data
template <- loadIIASATemplate(iiasatemplate)
expectedPriceIndices <- grep("^Price\\|.*\\|Index$", template$variable, value = TRUE)
missingPriceIndices <- setdiff(expectedPriceIndices, levels(mifdata$variable))
for (mpi in missingPriceIndices) {
templateunit <- unique(template$unit[template$variable == mpi])
referenceYear <- extractReferenceYear(templateunit, mpi)
mifdata <- priceIndicesAdd(mifdata, mpi, scenBase = scenBase, referenceYear = referenceYear)
}
return(mifdata)
}