From f47fcec33c00f1b94fb9763075f0489f0926ddc8 Mon Sep 17 00:00:00 2001 From: jvendries Date: Tue, 4 Nov 2025 20:11:38 -0500 Subject: [PATCH 1/3] Edit prepare2RDemand function to match consumption demand calculation in TestConsumtionDemand.R in USEEIO-State repo https://github.com/cornerstone-data/USEEIO-State/blob/1-ca-in-state-portion-of-cbe-appears-greater-than-ca-ghgi/scratch/TestConsumptionDemand.R#L45-L84 --- R/StateiorFunctions.R | 69 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 3 deletions(-) diff --git a/R/StateiorFunctions.R b/R/StateiorFunctions.R index 5c8cb24e..824b1d17 100644 --- a/R/StateiorFunctions.R +++ b/R/StateiorFunctions.R @@ -140,6 +140,7 @@ prepare2RDemand <- function(model, location, domestic, demand_type = "Production state_abb <- sub(".*/","",model$FinalDemandMeta$Code_Loc) ## Extract characters after / state_abb <- unique(state_abb) iolevel <- model$specs$BaseIOLevel + ita_column <- ifelse(iolevel == "Detail", "F05100", "F051") if(domestic) { # TODO: CHANGE domestic FROM BOOLEAN TO STRING WITH VALUES 'domestic', 'production', @@ -156,8 +157,13 @@ prepare2RDemand <- function(model, location, domestic, demand_type = "Production getVectorOfCodes, ioschema = model$specs$BaseIOSchema, iolevel = iolevel)) FD_columns <- FD_columns[FD_columns %in% gsub("/.*", "", model$FinalDemandMeta$Code_Loc)] + else if(demand_type == "Consumption") { + # Includes only household, investment, and government consumption as per Ingwersen et al. 2022 (USEEIOv2.0 paper) + FD_columns <- unlist(sapply(list("HouseholdDemand", "InvestmentDemand", "GovernmentDemand"), + getVectorOfCodes, ioschema = model$specs$BaseIOSchema, iolevel = iolevel)) + } + # Calculate production demand for both regions - ita_column <- ifelse(iolevel == "Detail", "F05100", "F051") if(location == state_abb[1]) { # calculate production final demand for SoI if(domestic) { @@ -179,11 +185,69 @@ prepare2RDemand <- function(model, location, domestic, demand_type = "Production y_p <- c(SoI2RoUS_y, RoUS2RoUS_y) } + names(y_p) <- model$Commodities$Code_Loc + return(y_p) +} + + + +#' Prepares a production demand vector representing production for two region models +#' Demand for SoI = SoI2SoI + RoUS2SoI +#' Demand for RoUS = SoI2RoUS + RoUS2RoUS +#' @param model An EEIO model object with model specs and IO tables loaded +#' @param location, str of location code for demand vector +#' @param domestic A logical parameter indicating whether to generate domestic demand vector. +#' @param demand_type A str indicating whether demand is Production or Consumption +#' @return A named vector with demand +prepare2RDemand_backup <- function(model, location, domestic, demand_type = "Production") { + # Get state abbreviations, e.g., "US-ME" and "RoUS" + state_abb <- sub(".*/","",model$FinalDemandMeta$Code_Loc) ## Extract characters after / + state_abb <- unique(state_abb) + iolevel <- model$specs$BaseIOLevel + + if(domestic) { + # TODO: CHANGE domestic FROM BOOLEAN TO STRING WITH VALUES 'domestic', 'production', + # and 'import', so we can calculate the import matrix in the following if else if else block + use_table <- model$DomesticUseTransactionswithTrade + } else { + use_table <- model$UseTransactionswithTrade + } + # Getting list of final demand columns used for the appropriate demand + if(demand_type == "Production") { + FD_columns <- unlist(sapply(list("HouseholdDemand", "InvestmentDemand", + "ChangeInventories", "Export", "Import", + "GovernmentDemand"), + getVectorOfCodes, ioschema = model$specs$BaseIOSchema, + iolevel = iolevel)) + FD_columns <- FD_columns[FD_columns %in% gsub("/.*", "", model$FinalDemandMeta$Code_Loc)] + # Calculate production demand for both regions + ita_column <- ifelse(iolevel == "Detail", "F05100", "F051") + if(location == state_abb[1]) { + # calculate production final demand for SoI + if(domestic) { + SoI2SoI_y <- rowSums(use_table[["SoI2SoI"]][, c(FD_columns, ita_column, "ExportResidual")]) + } else { + SoI2SoI_y <- rowSums(use_table[["SoI2SoI"]][, c(FD_columns, "ExportResidual")]) + } + RoUS2SoI_y <- rowSums(use_table[["RoUS2SoI"]][, c(FD_columns, ita_column)]) + y_p <- c(SoI2SoI_y, RoUS2SoI_y) + + } else if(location == state_abb[2]) { + # calculate production final demand for RoUS + if(domestic) { + RoUS2RoUS_y <- rowSums(use_table[["RoUS2RoUS"]][, c(FD_columns, ita_column, "ExportResidual")]) + } else { + RoUS2RoUS_y <- rowSums(use_table[["RoUS2RoUS"]][, c(FD_columns, "ExportResidual")]) + } + SoI2RoUS_y <- rowSums(use_table[["SoI2RoUS"]][, c(FD_columns, ita_column)]) + y_p <- c(SoI2RoUS_y, RoUS2RoUS_y) + } + } else if(demand_type == "Consumption") { # Includes only household, investment, and government consumption as per Ingwersen et al. 2022 (USEEIOv2.0 paper) FD_columns <- unlist(sapply(list("HouseholdDemand", "InvestmentDemand", "GovernmentDemand"), getVectorOfCodes, ioschema = model$specs$BaseIOSchema, iolevel = iolevel)) - + # Calculate consumption demand for both regions if(location == state_abb[1]) { # calculate consumption final demand for SoI @@ -201,7 +265,6 @@ prepare2RDemand <- function(model, location, domestic, demand_type = "Production return(y_p) } - #' Run validation checks for 2R models and print to console #' @param model A complete 2R EEIO model: a list with USEEIO model components and attributes print2RValidationResults <- function(model) { From 5b8acd24f31ddf07fa8029ec03e04aec92bafd99 Mon Sep 17 00:00:00 2001 From: jvendries Date: Tue, 4 Nov 2025 21:08:15 -0500 Subject: [PATCH 2/3] Fix typo in else if statement --- R/StateiorFunctions.R | 198 +++++++++++++++++++++--------------------- 1 file changed, 100 insertions(+), 98 deletions(-) diff --git a/R/StateiorFunctions.R b/R/StateiorFunctions.R index 824b1d17..3a4abce0 100644 --- a/R/StateiorFunctions.R +++ b/R/StateiorFunctions.R @@ -141,69 +141,6 @@ prepare2RDemand <- function(model, location, domestic, demand_type = "Production state_abb <- unique(state_abb) iolevel <- model$specs$BaseIOLevel ita_column <- ifelse(iolevel == "Detail", "F05100", "F051") - - if(domestic) { - # TODO: CHANGE domestic FROM BOOLEAN TO STRING WITH VALUES 'domestic', 'production', - # and 'import', so we can calculate the import matrix in the following if else if else block - use_table <- model$DomesticUseTransactionswithTrade - } else { - use_table <- model$UseTransactionswithTrade - } - # Getting list of final demand columns used for the appropriate demand - if(demand_type == "Production") { - FD_columns <- unlist(sapply(list("HouseholdDemand", "InvestmentDemand", - "ChangeInventories", "Export", "Import", - "GovernmentDemand"), - getVectorOfCodes, ioschema = model$specs$BaseIOSchema, - iolevel = iolevel)) - FD_columns <- FD_columns[FD_columns %in% gsub("/.*", "", model$FinalDemandMeta$Code_Loc)] - else if(demand_type == "Consumption") { - # Includes only household, investment, and government consumption as per Ingwersen et al. 2022 (USEEIOv2.0 paper) - FD_columns <- unlist(sapply(list("HouseholdDemand", "InvestmentDemand", "GovernmentDemand"), - getVectorOfCodes, ioschema = model$specs$BaseIOSchema, iolevel = iolevel)) - } - - # Calculate production demand for both regions - if(location == state_abb[1]) { - # calculate production final demand for SoI - if(domestic) { - SoI2SoI_y <- rowSums(use_table[["SoI2SoI"]][, c(FD_columns, ita_column, "ExportResidual")]) - } else { - SoI2SoI_y <- rowSums(use_table[["SoI2SoI"]][, c(FD_columns, "ExportResidual")]) - } - RoUS2SoI_y <- rowSums(use_table[["RoUS2SoI"]][, c(FD_columns, ita_column)]) - y_p <- c(SoI2SoI_y, RoUS2SoI_y) - - } else if(location == state_abb[2]) { - # calculate production final demand for RoUS - if(domestic) { - RoUS2RoUS_y <- rowSums(use_table[["RoUS2RoUS"]][, c(FD_columns, ita_column, "ExportResidual")]) - } else { - RoUS2RoUS_y <- rowSums(use_table[["RoUS2RoUS"]][, c(FD_columns, "ExportResidual")]) - } - SoI2RoUS_y <- rowSums(use_table[["SoI2RoUS"]][, c(FD_columns, ita_column)]) - y_p <- c(SoI2RoUS_y, RoUS2RoUS_y) - } - - names(y_p) <- model$Commodities$Code_Loc - return(y_p) -} - - - -#' Prepares a production demand vector representing production for two region models -#' Demand for SoI = SoI2SoI + RoUS2SoI -#' Demand for RoUS = SoI2RoUS + RoUS2RoUS -#' @param model An EEIO model object with model specs and IO tables loaded -#' @param location, str of location code for demand vector -#' @param domestic A logical parameter indicating whether to generate domestic demand vector. -#' @param demand_type A str indicating whether demand is Production or Consumption -#' @return A named vector with demand -prepare2RDemand_backup <- function(model, location, domestic, demand_type = "Production") { - # Get state abbreviations, e.g., "US-ME" and "RoUS" - state_abb <- sub(".*/","",model$FinalDemandMeta$Code_Loc) ## Extract characters after / - state_abb <- unique(state_abb) - iolevel <- model$specs$BaseIOLevel if(domestic) { # TODO: CHANGE domestic FROM BOOLEAN TO STRING WITH VALUES 'domestic', 'production', @@ -220,51 +157,116 @@ prepare2RDemand_backup <- function(model, location, domestic, demand_type = "Pro getVectorOfCodes, ioschema = model$specs$BaseIOSchema, iolevel = iolevel)) FD_columns <- FD_columns[FD_columns %in% gsub("/.*", "", model$FinalDemandMeta$Code_Loc)] - # Calculate production demand for both regions - ita_column <- ifelse(iolevel == "Detail", "F05100", "F051") - if(location == state_abb[1]) { - # calculate production final demand for SoI - if(domestic) { - SoI2SoI_y <- rowSums(use_table[["SoI2SoI"]][, c(FD_columns, ita_column, "ExportResidual")]) - } else { - SoI2SoI_y <- rowSums(use_table[["SoI2SoI"]][, c(FD_columns, "ExportResidual")]) - } - RoUS2SoI_y <- rowSums(use_table[["RoUS2SoI"]][, c(FD_columns, ita_column)]) - y_p <- c(SoI2SoI_y, RoUS2SoI_y) - - } else if(location == state_abb[2]) { - # calculate production final demand for RoUS - if(domestic) { - RoUS2RoUS_y <- rowSums(use_table[["RoUS2RoUS"]][, c(FD_columns, ita_column, "ExportResidual")]) - } else { - RoUS2RoUS_y <- rowSums(use_table[["RoUS2RoUS"]][, c(FD_columns, "ExportResidual")]) - } - SoI2RoUS_y <- rowSums(use_table[["SoI2RoUS"]][, c(FD_columns, ita_column)]) - y_p <- c(SoI2RoUS_y, RoUS2RoUS_y) - } - - } else if(demand_type == "Consumption") { + } + else if(demand_type == "Consumption") { # Includes only household, investment, and government consumption as per Ingwersen et al. 2022 (USEEIOv2.0 paper) FD_columns <- unlist(sapply(list("HouseholdDemand", "InvestmentDemand", "GovernmentDemand"), getVectorOfCodes, ioschema = model$specs$BaseIOSchema, iolevel = iolevel)) + } - # Calculate consumption demand for both regions - if(location == state_abb[1]) { - # calculate consumption final demand for SoI - SoI2SoI_y <- rowSums(use_table[["SoI2SoI"]][, c(FD_columns)]) - RoUS2SoI_y <- rowSums(use_table[["RoUS2SoI"]][, c(FD_columns)]) - y_p <- c(SoI2SoI_y, RoUS2SoI_y) - } else if(location == state_abb[2]) { - # calculate consumption final demand for RoUS - SoI2RoUS_y <- rowSums(use_table[["SoI2RoUS"]][, c(FD_columns)]) - RoUS2RoUS_y <- rowSums(use_table[["RoUS2RoUS"]][, c(FD_columns)]) - y_p <- c(SoI2RoUS_y, RoUS2RoUS_y) + # Calculate production demand for both regions + if(location == state_abb[1]) { + # calculate production final demand for SoI + if(domestic) { + SoI2SoI_y <- rowSums(use_table[["SoI2SoI"]][, c(FD_columns, ita_column, "ExportResidual")]) + } else { + SoI2SoI_y <- rowSums(use_table[["SoI2SoI"]][, c(FD_columns, "ExportResidual")]) } + RoUS2SoI_y <- rowSums(use_table[["RoUS2SoI"]][, c(FD_columns, ita_column)]) + y_p <- c(SoI2SoI_y, RoUS2SoI_y) + + } else if(location == state_abb[2]) { + # calculate production final demand for RoUS + if(domestic) { + RoUS2RoUS_y <- rowSums(use_table[["RoUS2RoUS"]][, c(FD_columns, ita_column, "ExportResidual")]) + } else { + RoUS2RoUS_y <- rowSums(use_table[["RoUS2RoUS"]][, c(FD_columns, "ExportResidual")]) + } + SoI2RoUS_y <- rowSums(use_table[["SoI2RoUS"]][, c(FD_columns, ita_column)]) + y_p <- c(SoI2RoUS_y, RoUS2RoUS_y) } + names(y_p) <- model$Commodities$Code_Loc return(y_p) } + + +#' #' Prepares a production demand vector representing production for two region models +#' #' Demand for SoI = SoI2SoI + RoUS2SoI +#' #' Demand for RoUS = SoI2RoUS + RoUS2RoUS +#' #' @param model An EEIO model object with model specs and IO tables loaded +#' #' @param location, str of location code for demand vector +#' #' @param domestic A logical parameter indicating whether to generate domestic demand vector. +#' #' @param demand_type A str indicating whether demand is Production or Consumption +#' #' @return A named vector with demand +#' prepare2RDemand <- function(model, location, domestic, demand_type = "Production") { +#' # OLD FUNCTION +#' # Get state abbreviations, e.g., "US-ME" and "RoUS" +#' state_abb <- sub(".*/","",model$FinalDemandMeta$Code_Loc) ## Extract characters after / +#' state_abb <- unique(state_abb) +#' iolevel <- model$specs$BaseIOLevel +#' +#' if(domestic) { +#' # TODO: CHANGE domestic FROM BOOLEAN TO STRING WITH VALUES 'domestic', 'production', +#' # and 'import', so we can calculate the import matrix in the following if else if else block +#' use_table <- model$DomesticUseTransactionswithTrade +#' } else { +#' use_table <- model$UseTransactionswithTrade +#' } +#' # Getting list of final demand columns used for the appropriate demand +#' if(demand_type == "Production") { +#' FD_columns <- unlist(sapply(list("HouseholdDemand", "InvestmentDemand", +#' "ChangeInventories", "Export", "Import", +#' "GovernmentDemand"), +#' getVectorOfCodes, ioschema = model$specs$BaseIOSchema, +#' iolevel = iolevel)) +#' FD_columns <- FD_columns[FD_columns %in% gsub("/.*", "", model$FinalDemandMeta$Code_Loc)] +#' # Calculate production demand for both regions +#' ita_column <- ifelse(iolevel == "Detail", "F05100", "F051") +#' if(location == state_abb[1]) { +#' # calculate production final demand for SoI +#' if(domestic) { +#' SoI2SoI_y <- rowSums(use_table[["SoI2SoI"]][, c(FD_columns, ita_column, "ExportResidual")]) +#' } else { +#' SoI2SoI_y <- rowSums(use_table[["SoI2SoI"]][, c(FD_columns, "ExportResidual")]) +#' } +#' RoUS2SoI_y <- rowSums(use_table[["RoUS2SoI"]][, c(FD_columns, ita_column)]) +#' y_p <- c(SoI2SoI_y, RoUS2SoI_y) +#' +#' } else if(location == state_abb[2]) { +#' # calculate production final demand for RoUS +#' if(domestic) { +#' RoUS2RoUS_y <- rowSums(use_table[["RoUS2RoUS"]][, c(FD_columns, ita_column, "ExportResidual")]) +#' } else { +#' RoUS2RoUS_y <- rowSums(use_table[["RoUS2RoUS"]][, c(FD_columns, "ExportResidual")]) +#' } +#' SoI2RoUS_y <- rowSums(use_table[["SoI2RoUS"]][, c(FD_columns, ita_column)]) +#' y_p <- c(SoI2RoUS_y, RoUS2RoUS_y) +#' } +#' +#' } else if(demand_type == "Consumption") { +#' # Includes only household, investment, and government consumption as per Ingwersen et al. 2022 (USEEIOv2.0 paper) +#' FD_columns <- unlist(sapply(list("HouseholdDemand", "InvestmentDemand", "GovernmentDemand"), +#' getVectorOfCodes, ioschema = model$specs$BaseIOSchema, iolevel = iolevel)) +#' +#' # Calculate consumption demand for both regions +#' if(location == state_abb[1]) { +#' # calculate consumption final demand for SoI +#' SoI2SoI_y <- rowSums(use_table[["SoI2SoI"]][, c(FD_columns)]) +#' RoUS2SoI_y <- rowSums(use_table[["RoUS2SoI"]][, c(FD_columns)]) +#' y_p <- c(SoI2SoI_y, RoUS2SoI_y) +#' } else if(location == state_abb[2]) { +#' # calculate consumption final demand for RoUS +#' SoI2RoUS_y <- rowSums(use_table[["SoI2RoUS"]][, c(FD_columns)]) +#' RoUS2RoUS_y <- rowSums(use_table[["RoUS2RoUS"]][, c(FD_columns)]) +#' y_p <- c(SoI2RoUS_y, RoUS2RoUS_y) +#' } +#' } +#' names(y_p) <- model$Commodities$Code_Loc +#' return(y_p) +#' } + #' Run validation checks for 2R models and print to console #' @param model A complete 2R EEIO model: a list with USEEIO model components and attributes print2RValidationResults <- function(model) { From 86d8453487adab39c841a1fbfd8523ed0bec6059 Mon Sep 17 00:00:00 2001 From: WesIngwersen Date: Thu, 6 Nov 2025 15:52:10 -0500 Subject: [PATCH 3/3] Use y instead of y_p. Drop production from comments when not applicable. Remove old function. --- R/StateiorFunctions.R | 92 +++++-------------------------------------- 1 file changed, 9 insertions(+), 83 deletions(-) diff --git a/R/StateiorFunctions.R b/R/StateiorFunctions.R index 3a4abce0..b1dff3c4 100644 --- a/R/StateiorFunctions.R +++ b/R/StateiorFunctions.R @@ -164,109 +164,35 @@ prepare2RDemand <- function(model, location, domestic, demand_type = "Production getVectorOfCodes, ioschema = model$specs$BaseIOSchema, iolevel = iolevel)) } - # Calculate production demand for both regions + # Prepare demand for state models which have additional fields for ITA and Export Residual + # State with SoI if(location == state_abb[1]) { - # calculate production final demand for SoI + # calculate final demand for SoI if(domestic) { SoI2SoI_y <- rowSums(use_table[["SoI2SoI"]][, c(FD_columns, ita_column, "ExportResidual")]) } else { SoI2SoI_y <- rowSums(use_table[["SoI2SoI"]][, c(FD_columns, "ExportResidual")]) } RoUS2SoI_y <- rowSums(use_table[["RoUS2SoI"]][, c(FD_columns, ita_column)]) - y_p <- c(SoI2SoI_y, RoUS2SoI_y) + y <- c(SoI2SoI_y, RoUS2SoI_y) + # For RoUS } else if(location == state_abb[2]) { - # calculate production final demand for RoUS + # calculate final demand for RoUS if(domestic) { RoUS2RoUS_y <- rowSums(use_table[["RoUS2RoUS"]][, c(FD_columns, ita_column, "ExportResidual")]) } else { RoUS2RoUS_y <- rowSums(use_table[["RoUS2RoUS"]][, c(FD_columns, "ExportResidual")]) } SoI2RoUS_y <- rowSums(use_table[["SoI2RoUS"]][, c(FD_columns, ita_column)]) - y_p <- c(SoI2RoUS_y, RoUS2RoUS_y) + y <- c(SoI2RoUS_y, RoUS2RoUS_y) } - names(y_p) <- model$Commodities$Code_Loc - return(y_p) + names(y) <- model$Commodities$Code_Loc + return(y) } - -#' #' Prepares a production demand vector representing production for two region models -#' #' Demand for SoI = SoI2SoI + RoUS2SoI -#' #' Demand for RoUS = SoI2RoUS + RoUS2RoUS -#' #' @param model An EEIO model object with model specs and IO tables loaded -#' #' @param location, str of location code for demand vector -#' #' @param domestic A logical parameter indicating whether to generate domestic demand vector. -#' #' @param demand_type A str indicating whether demand is Production or Consumption -#' #' @return A named vector with demand -#' prepare2RDemand <- function(model, location, domestic, demand_type = "Production") { -#' # OLD FUNCTION -#' # Get state abbreviations, e.g., "US-ME" and "RoUS" -#' state_abb <- sub(".*/","",model$FinalDemandMeta$Code_Loc) ## Extract characters after / -#' state_abb <- unique(state_abb) -#' iolevel <- model$specs$BaseIOLevel -#' -#' if(domestic) { -#' # TODO: CHANGE domestic FROM BOOLEAN TO STRING WITH VALUES 'domestic', 'production', -#' # and 'import', so we can calculate the import matrix in the following if else if else block -#' use_table <- model$DomesticUseTransactionswithTrade -#' } else { -#' use_table <- model$UseTransactionswithTrade -#' } -#' # Getting list of final demand columns used for the appropriate demand -#' if(demand_type == "Production") { -#' FD_columns <- unlist(sapply(list("HouseholdDemand", "InvestmentDemand", -#' "ChangeInventories", "Export", "Import", -#' "GovernmentDemand"), -#' getVectorOfCodes, ioschema = model$specs$BaseIOSchema, -#' iolevel = iolevel)) -#' FD_columns <- FD_columns[FD_columns %in% gsub("/.*", "", model$FinalDemandMeta$Code_Loc)] -#' # Calculate production demand for both regions -#' ita_column <- ifelse(iolevel == "Detail", "F05100", "F051") -#' if(location == state_abb[1]) { -#' # calculate production final demand for SoI -#' if(domestic) { -#' SoI2SoI_y <- rowSums(use_table[["SoI2SoI"]][, c(FD_columns, ita_column, "ExportResidual")]) -#' } else { -#' SoI2SoI_y <- rowSums(use_table[["SoI2SoI"]][, c(FD_columns, "ExportResidual")]) -#' } -#' RoUS2SoI_y <- rowSums(use_table[["RoUS2SoI"]][, c(FD_columns, ita_column)]) -#' y_p <- c(SoI2SoI_y, RoUS2SoI_y) -#' -#' } else if(location == state_abb[2]) { -#' # calculate production final demand for RoUS -#' if(domestic) { -#' RoUS2RoUS_y <- rowSums(use_table[["RoUS2RoUS"]][, c(FD_columns, ita_column, "ExportResidual")]) -#' } else { -#' RoUS2RoUS_y <- rowSums(use_table[["RoUS2RoUS"]][, c(FD_columns, "ExportResidual")]) -#' } -#' SoI2RoUS_y <- rowSums(use_table[["SoI2RoUS"]][, c(FD_columns, ita_column)]) -#' y_p <- c(SoI2RoUS_y, RoUS2RoUS_y) -#' } -#' -#' } else if(demand_type == "Consumption") { -#' # Includes only household, investment, and government consumption as per Ingwersen et al. 2022 (USEEIOv2.0 paper) -#' FD_columns <- unlist(sapply(list("HouseholdDemand", "InvestmentDemand", "GovernmentDemand"), -#' getVectorOfCodes, ioschema = model$specs$BaseIOSchema, iolevel = iolevel)) -#' -#' # Calculate consumption demand for both regions -#' if(location == state_abb[1]) { -#' # calculate consumption final demand for SoI -#' SoI2SoI_y <- rowSums(use_table[["SoI2SoI"]][, c(FD_columns)]) -#' RoUS2SoI_y <- rowSums(use_table[["RoUS2SoI"]][, c(FD_columns)]) -#' y_p <- c(SoI2SoI_y, RoUS2SoI_y) -#' } else if(location == state_abb[2]) { -#' # calculate consumption final demand for RoUS -#' SoI2RoUS_y <- rowSums(use_table[["SoI2RoUS"]][, c(FD_columns)]) -#' RoUS2RoUS_y <- rowSums(use_table[["RoUS2RoUS"]][, c(FD_columns)]) -#' y_p <- c(SoI2RoUS_y, RoUS2RoUS_y) -#' } -#' } -#' names(y_p) <- model$Commodities$Code_Loc -#' return(y_p) -#' } - #' Run validation checks for 2R models and print to console #' @param model A complete 2R EEIO model: a list with USEEIO model components and attributes print2RValidationResults <- function(model) {