From 98b848bd86ded3a312c39213260c67446213eb55 Mon Sep 17 00:00:00 2001 From: Ben Young Date: Fri, 17 May 2024 14:56:35 -0400 Subject: [PATCH] rename `buildEIOModel` to `buildIOModel` and export; incorporate adjustment for 2r models --- NAMESPACE | 1 + R/BuildModel.R | 17 ++++++++++++----- man/{buildEIOModel.Rd => buildIOModel.Rd} | 12 ++++++------ tests/test_model_build.R | 4 ++-- 4 files changed, 21 insertions(+), 13 deletions(-) rename man/{buildEIOModel.Rd => buildIOModel.Rd} (60%) diff --git a/NAMESPACE b/NAMESPACE index 2518e067..7ad8e510 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,6 +5,7 @@ export(aggregateResultMatrix) export(aggregateResultMatrixbyRow) export(barplotFloworImpactFractionbyRegion) export(barplotIndicatorScoresbySector) +export(buildIOModel) export(buildModel) export(buildTwoRegionModels) export(calculateEEIOModel) diff --git a/R/BuildModel.R b/R/BuildModel.R index b2020ef2..a71954d3 100644 --- a/R/BuildModel.R +++ b/R/BuildModel.R @@ -285,12 +285,13 @@ buildTwoRegionModels <- function(modelname, configpaths = NULL, validate = FALSE return(model_ls) } -#' Build an EIO model with economic components only. +#' Build an IO model with economic components only. #' @param modelname Name of the model from a config file. #' @param configpaths str vector, paths (including file name) of model configuration file #' and optional agg/disagg configuration file(s). If NULL, built-in config files are used. -#' @return A list of EIO model with only economic components -buildEIOModel <- function(modelname, configpaths = NULL) { +#' @return A list of IO model with only economic components +#' @export +buildIOModel <- function(modelname, configpaths = NULL) { model <- initializeModel(modelname, configpaths) model <- loadIOData(model, configpaths) model <- loadDemandVectors(model) @@ -314,8 +315,14 @@ buildEIOModel <- function(modelname, configpaths = NULL) { colnames(model$U_d) <- colnames(model$U) model[c("U", "U_d")] <- lapply(model[c("U", "U_d")], function(x) ifelse(is.na(x), 0, x)) - model$U_n <- generateDirectRequirementsfromUse(model, domestic = FALSE) #normalized Use - model$U_d_n <- generateDirectRequirementsfromUse(model, domestic = TRUE) #normalized DomesticUse + + if (model$specs$IODataSource=="stateior") { + model$U_n <- generate2RDirectRequirementsfromUseWithTrade(model, domestic = FALSE) + model$U_d_n <- generate2RDirectRequirementsfromUseWithTrade(model, domestic = TRUE) + } else { + model$U_n <- generateDirectRequirementsfromUse(model, domestic = FALSE) #normalized Use + model$U_d_n <- generateDirectRequirementsfromUse(model, domestic = TRUE) #normalized DomesticUse + } model$q <- model$CommodityOutput model$x <- model$IndustryOutput model$mu <- model$InternationalTradeAdjustment diff --git a/man/buildEIOModel.Rd b/man/buildIOModel.Rd similarity index 60% rename from man/buildEIOModel.Rd rename to man/buildIOModel.Rd index 49abb9b0..10ca8009 100644 --- a/man/buildEIOModel.Rd +++ b/man/buildIOModel.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/BuildModel.R -\name{buildEIOModel} -\alias{buildEIOModel} -\title{Build an EIO model with economic components only.} +\name{buildIOModel} +\alias{buildIOModel} +\title{Build an IO model with economic components only.} \usage{ -buildEIOModel(modelname, configpaths = NULL) +buildIOModel(modelname, configpaths = NULL) } \arguments{ \item{modelname}{Name of the model from a config file.} @@ -13,8 +13,8 @@ buildEIOModel(modelname, configpaths = NULL) and optional agg/disagg configuration file(s). If NULL, built-in config files are used.} } \value{ -A list of EIO model with only economic components +A list of IO model with only economic components } \description{ -Build an EIO model with economic components only. +Build an IO model with economic components only. } diff --git a/tests/test_model_build.R b/tests/test_model_build.R index 8aa96799..d6865b49 100644 --- a/tests/test_model_build.R +++ b/tests/test_model_build.R @@ -13,7 +13,7 @@ printValidationResults(model) ## USEEIOv2.0.1-411 Detail model with waste disaggregation (Economic only) m <- "USEEIOv2.0.1-411" -model <- buildEIOModel(m) +model <- buildIOModel(m) printValidationResults(model) writeModeltoXLSX(model, ".") @@ -121,6 +121,6 @@ model <- buildModel(m, configpaths = file.path(cfg)) useeior::print2RValidationResults(model) ## StateEEIOv1.0 Two-region Summary model -model <- buildEIOModel(m, configpaths = file.path(cfg)) +model <- buildIOModel(m, configpaths = file.path(cfg)) useeior::print2RValidationResults(model) writeModeltoXLSX(model, ".")