From dde2d8fd16d6a87386bee65cedbd04ef09aed7be Mon Sep 17 00:00:00 2001 From: Ben Young Date: Wed, 15 May 2024 21:47:31 -0400 Subject: [PATCH] can't construct Phi if no margins, #290 --- R/BuildModel.R | 8 +++++--- R/WriteModel.R | 7 +++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/R/BuildModel.R b/R/BuildModel.R index 9c0cbcfc..c1cd4fe7 100644 --- a/R/BuildModel.R +++ b/R/BuildModel.R @@ -109,9 +109,11 @@ constructEEIOMatrices <- function(model, configpaths = NULL) { logging::loginfo("Calculating Rho matrix (price year ratio)...") model$Rho <- calculateModelIOYearbyYearPriceRatio(model) - # Calculate producer over purchaser price ratio. - logging::loginfo("Calculating Phi matrix (producer over purchaser price ratio)...") - model$Phi <- calculateProducerbyPurchaserPriceRatio(model) + if (model$specs$IODataSource!="stateior") { + # Calculate producer over purchaser price ratio. + logging::loginfo("Calculating Phi matrix (producer over purchaser price ratio)...") + model$Phi <- calculateProducerbyPurchaserPriceRatio(model) + } # Calculate basic over producer price ratio. logging::loginfo("Calculating Tau matrix (basic over producer price ratio)...") diff --git a/R/WriteModel.R b/R/WriteModel.R index 514cd550..71a12ae4 100644 --- a/R/WriteModel.R +++ b/R/WriteModel.R @@ -285,8 +285,11 @@ writeModelMetadata <- function(model, dirs) { years <- data.frame(ID=colnames(model$Rho), stringsAsFactors = FALSE) years$Index <- c(1:length(years$ID)-1) years <- years[, fields$years] - checkNamesandOrdering(years$ID, colnames(model$Phi), - "years in years.csv and cols in Phi matrix") + + if(!is.null(model$Phi)) { + checkNamesandOrdering(years$ID, colnames(model$Phi), + "years in years.csv and cols in Phi matrix") + } checkNamesandOrdering(years$ID, colnames(model$Rho), "years in years.csv and cols in Rho matrix") utils::write.csv(years, paste0(dirs$model, "/years.csv"), na = "",