From 634b1b3f0bdc6d238103ebea997f42436b226e3f Mon Sep 17 00:00:00 2001 From: Ben Young Date: Thu, 16 Nov 2023 08:39:22 -0500 Subject: [PATCH] cleanup and update documentation --- R/IOFunctions.R | 24 ------------------------ R/LoadExternalImportFactors.R | 8 +++----- R/LoadIOTables.R | 3 +-- man/calculateAndValidateImportA.Rd | 2 +- man/loadExternalImportFactors.Rd | 11 ++++------- man/loadImportMatrix.Rd | 19 +++++++++++++++++++ 6 files changed, 28 insertions(+), 39 deletions(-) create mode 100644 man/loadImportMatrix.Rd diff --git a/R/IOFunctions.R b/R/IOFunctions.R index 67f4864f..5cbba940 100644 --- a/R/IOFunctions.R +++ b/R/IOFunctions.R @@ -174,19 +174,6 @@ calculateLeontiefInverse <- function(A) { #' @param model, An EEIO model object with model specs and crosswalk table loaded #' @return A Domestic Use table with rows as commodity codes and columns as industry and final demand codes generateDomesticUse <- function(Use, model) { - # Load Import matrix - - # if (model$specs$BaseIOLevel != "Sector") { - # Import <- get(paste(model$specs$BaseIOLevel, "Import", - # model$specs$IOYear, "BeforeRedef", sep = "_"))*1E6 - # } else { - # # Load Summary level Import matrix - # Import <- get(paste("Summary_Import", model$specs$IOYear, "BeforeRedef", sep = "_"))*1E6 - # # Aggregate Import from Summary to Sector - # Import <- as.data.frame(aggregateMatrix(as.matrix(Import), "Summary", "Sector", model)) - # } - # Import <- Import[rownames(Use), colnames(Use)] - Import <- model$ImportMatrix # Adjust Import matrix to BAS price if model is in BAS price # Note: according to the documentation in BEA Import matrix, import values in @@ -231,17 +218,6 @@ generateDomesticUse <- function(Use, model) { #' @param model, An EEIO model object with model specs and crosswalk table loaded #' @return An international trade adjustment vector with names as commodity codes generateInternationalTradeAdjustmentVector <- function(Use, model) { - # Load Import matrix - - # if (model$specs$BaseIOLevel!="Sector") { - # Import <- get(paste(model$specs$BaseIOLevel, "Import", model$specs$IOYear, "BeforeRedef", sep = "_"))*1E6 - # } else { - # # Load Summary level Import matrix - # Import <- get(paste("Summary_Import", model$specs$IOYear, "BeforeRedef", sep = "_"))*1E6 - # # Aggregate Import from Summary to Sector - # Import <- as.data.frame(aggregateMatrix(as.matrix(Import), "Summary", "Sector", model)) - # } - Import <- model$ImportMatrix # Define Import code ImportCode <- getVectorOfCodes(model$specs$BaseIOSchema, model$specs$BaseIOLevel, "Import") diff --git a/R/LoadExternalImportFactors.R b/R/LoadExternalImportFactors.R index 0b1f82b6..82b2f293 100644 --- a/R/LoadExternalImportFactors.R +++ b/R/LoadExternalImportFactors.R @@ -1,11 +1,9 @@ # Functions for loading external import factors -#' Prepare economic components of an EEIO form USEEIO model. +#' Load and prepare import coefficients #' @param model An EEIO form USEEIO model object with model specs loaded -#' @param configpaths str vector, paths (including file name) of model configuration file -#' If NULL, built-in config files are used. -#' @return A list with EEIO form USEEIO model economic components. -loadExternalImportFactors <- function(model, configpaths = NULL) { +#' @return M_m, matrix of import coefficients (flow x sector). +loadExternalImportFactors <- function(model) { # Read in file with Import factors IFSpec <- model$specs$ImportFactors[[1]] diff --git a/R/LoadIOTables.R b/R/LoadIOTables.R index 3b83af40..8d18099b 100644 --- a/R/LoadIOTables.R +++ b/R/LoadIOTables.R @@ -186,7 +186,6 @@ loadNationalIOData <- function(model, io_codes) { io_codes$FinalDemandCodes <- colnames(BEA$FinalDemand) BEA$ImportMatrix <- loadImportMatrix(model, io_codes) - model$ImportMatrix <- BEA$ImportMatrix # Generate domestic Use transaction and final demand DomesticUse <- generateDomesticUse(cbind(BEA$UseTransactions, BEA$FinalDemand), model) @@ -295,7 +294,7 @@ loadBEAtables <- function(specs, io_codes) { #' Load, format, and save import matrix as a USEEIO model object. #' @param model A model object with model specs loaded. #' @param io_codes A list of BEA IO codes. -#' @return A USEEIO model with import matrix object. +#' @return Import, a use table import matrix. loadImportMatrix <- function(model, io_codes) { # Load Import matrix if (model$specs$BaseIOLevel != "Sector") { diff --git a/man/calculateAndValidateImportA.Rd b/man/calculateAndValidateImportA.Rd index fa1929ae..ad0fca01 100644 --- a/man/calculateAndValidateImportA.Rd +++ b/man/calculateAndValidateImportA.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/IOFunctions.R +% Please edit documentation in R/ValidateModel.R \name{calculateAndValidateImportA} \alias{calculateAndValidateImportA} \title{Create import direct requirements table based on import use and import y tables} diff --git a/man/loadExternalImportFactors.Rd b/man/loadExternalImportFactors.Rd index 2f4ef229..d921f402 100644 --- a/man/loadExternalImportFactors.Rd +++ b/man/loadExternalImportFactors.Rd @@ -2,19 +2,16 @@ % Please edit documentation in R/LoadExternalImportFactors.R \name{loadExternalImportFactors} \alias{loadExternalImportFactors} -\title{Prepare economic components of an EEIO form USEEIO model.} +\title{Load and prepare import coefficients} \usage{ -loadExternalImportFactors(model, configpaths = NULL) +loadExternalImportFactors(model) } \arguments{ \item{model}{An EEIO form USEEIO model object with model specs loaded} - -\item{configpaths}{str vector, paths (including file name) of model configuration file -If NULL, built-in config files are used.} } \value{ -A list with EEIO form USEEIO model economic components. +M_m, matrix of import coefficients (flow x sector). } \description{ -Prepare economic components of an EEIO form USEEIO model. +Load and prepare import coefficients } diff --git a/man/loadImportMatrix.Rd b/man/loadImportMatrix.Rd new file mode 100644 index 00000000..13ec2159 --- /dev/null +++ b/man/loadImportMatrix.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/LoadIOTables.R +\name{loadImportMatrix} +\alias{loadImportMatrix} +\title{Load, format, and save import matrix as a USEEIO model object.} +\usage{ +loadImportMatrix(model, io_codes) +} +\arguments{ +\item{model}{A model object with model specs loaded.} + +\item{io_codes}{A list of BEA IO codes.} +} +\value{ +Import, a use table import matrix. +} +\description{ +Load, format, and save import matrix as a USEEIO model object. +}