Skip to content

Commit

Permalink
Add code to handle the case when default disaggregation percentages r…
Browse files Browse the repository at this point in the history
…esult in a NA dataframe.

This occurs when the default disaggregation percentages are missing from the input files but all disaggregations splits are accounted for in the same files (e.g., when doing Summary to Detail disaggs)
  • Loading branch information
jvendries committed Oct 29, 2024
1 parent 2b170e7 commit 224856a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions R/DisaggregateFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -1485,8 +1485,12 @@ getDefaultAllocationPercentages <- function(FileDF, disagg, numNewSectors, outpu
defaultPercentages <- defaultPercentages[match(disagg$NewSectorCodes, defaultPercentages$CommodityCode),]
}

#If there are no default percentages from values from csv (i.e. number of rows in defaultRowPercentages dataframe is 0) assume uniform split, otherwise use the csv values
if(nrow(defaultPercentages)==0) {
#If there are no default percentages from values from csv (i.e. number of rows in defaultRowPercentages dataframe is 0 or dataframe is all NAs),
# assume uniform split, otherwise use the csv values
if(nrow(defaultPercentages)==0 || all(is.na(defaultPercentages))) {
#Note: The second part of the if state added for use in Summary to Detail disaggregations, where no
# default percentages are provided but disaggregation splits for all values are
#TODO: Consider changing this function to not use uniform split but a split based on % of total output of disagg sectors if available.
#Uniform split
defaultPercentages <- data.frame(rep(1/numNewSectors, numNewSectors))
} else {
Expand Down

0 comments on commit 224856a

Please sign in to comment.