From a2f5dd2f318b913e9ae71c54c62965620831bf5a Mon Sep 17 00:00:00 2001 From: Tony Gardella Date: Fri, 5 Jan 2024 14:05:37 -0500 Subject: [PATCH 1/3] fixes to get 2300 working --- FrEDI/R/import_inputs.R | 8 ++++---- FrEDI/R/utils.R | 9 ++++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/FrEDI/R/import_inputs.R b/FrEDI/R/import_inputs.R index af4f49b1..87aeb150 100644 --- a/FrEDI/R/import_inputs.R +++ b/FrEDI/R/import_inputs.R @@ -115,7 +115,7 @@ import_inputs <- function( ###### Initialize Inputs List ###### ### Get input scenario info: co_inputScenarioInfo name_dfScenarioInfo <- "co_inputScenarioInfo" - assign(name_dfScenarioInfo, rDataList[["regionData"]][["data"]][[name_dfScenarioInfo]]) + assign(name_dfScenarioInfo, rDataList[["frediData"]][["data"]][[name_dfScenarioInfo]]) name_stateInfo <- "co_states" assign(name_stateInfo, rDataList[["frediData"]][["data"]][[name_stateInfo]]) input_names_vector <- co_inputScenarioInfo$inputName @@ -149,7 +149,7 @@ import_inputs <- function( cols0 <- statecols0 colNames_i <- numCols_i <- c("year", "state_pop") } - + ### Add state/region columns as needed if(region_i == 1){ colNames_i <- c(colNames_i[1], cols0, colNames_i[2]) @@ -202,9 +202,9 @@ import_inputs <- function( if(byState){ df_input_i <- df_input_i |> left_join(co_states, by = c("state" = "state"), suffix = c("", ".y")) |> - select(colNames_i) + select(colNames_i) } - + df_input_i <- df_input_i |> rename_inputs(colNames_i) |> mutate_all(as.character) |> diff --git a/FrEDI/R/utils.R b/FrEDI/R/utils.R index a3106d65..293f1c09 100644 --- a/FrEDI/R/utils.R +++ b/FrEDI/R/utils.R @@ -341,7 +341,9 @@ extend_slrScalars <- function( ### Update exponent if(!(elasticity |> is.null())){ # df_scalars <- df_scalars |> mutate(exp0 = (exp0 == 1) |> ifelse(exp0, elasticity)) - df_scalars <- df_scalars |> mutate(exp0 = (econScalarName=="vsl_usd") |> ifelse(elasticity, exp0)) + #df_scalars <- df_scalars |> mutate(exp0 = (econScalarName=="vsl_usd") |> ifelse(elasticity, exp0)) + df_scalars <- df_scalars |> mutate(exp0 = case_when(scalarName == "vsl_usd" ~ elasticity, + .default = NA)) } ### End if(!(elasticity |> is.null())) ###### By State ###### @@ -777,8 +779,9 @@ initialize_resultsDf <- function( df_slr2 <- df_slr2 |> filter(year > refYear0) ### Add results back together - df_slr0 <- df_slr1 |> rbind(df_slr2) - df0 <- df_gcm0 |> rbind(df_slr0) + df_slr0 <- df_slr1 |> bind_rows(df_slr2) + df0 <- df_gcm0 |> bind_rows(df_slr0) + rm(df_slr1, df_slr2, df_slr0, df_gcm0) } ### End if(do_npd) From 175a1012bb86bb5c6259f2c33d2b8d567690dc0d Mon Sep 17 00:00:00 2001 From: Karen Noiva Date: Fri, 5 Jan 2024 15:34:42 -0500 Subject: [PATCH 2/3] Update run_fredi.R Dropped "modelUnitType" from group columns (already have "unitType") --- FrEDI/R/run_fredi.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FrEDI/R/run_fredi.R b/FrEDI/R/run_fredi.R index 7d95560b..907b454a 100644 --- a/FrEDI/R/run_fredi.R +++ b/FrEDI/R/run_fredi.R @@ -675,7 +675,7 @@ run_fredi <- function( ### Grouping columns groupCols0 <- c("sector", "variant", "impactType", "impactYear", "region") |> c(stateCols0) groupCols0 <- groupCols0 |> c("model_type", "model") - groupCols0 <- groupCols0 |> c("modelUnitType") + # groupCols0 <- groupCols0 |> c("modelUnitType") groupCols0 <- groupCols0 |> c("sectorprimary", "includeaggregate") groupCols0 <- groupCols0 |> c("physicalmeasure") groupCols0 <- groupCols0 |> (function(x){x[!(x %in% (x |> names()))]})() From 149e80bd07a971aa007543299c11b976279e3065 Mon Sep 17 00:00:00 2001 From: Karen Noiva Date: Fri, 5 Jan 2024 15:39:46 -0500 Subject: [PATCH 3/3] Update utils.R Moved step for updating elasticity with a custom elasticity. --- FrEDI/R/utils.R | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/FrEDI/R/utils.R b/FrEDI/R/utils.R index 293f1c09..452d5241 100644 --- a/FrEDI/R/utils.R +++ b/FrEDI/R/utils.R @@ -337,15 +337,6 @@ extend_slrScalars <- function( df_scalars, ### Main scalar values: df_mainScalars elasticity = NULL ){ - ###### Elasticity ###### - ### Update exponent - if(!(elasticity |> is.null())){ - # df_scalars <- df_scalars |> mutate(exp0 = (exp0 == 1) |> ifelse(exp0, elasticity)) - #df_scalars <- df_scalars |> mutate(exp0 = (econScalarName=="vsl_usd") |> ifelse(elasticity, exp0)) - df_scalars <- df_scalars |> mutate(exp0 = case_when(scalarName == "vsl_usd" ~ elasticity, - .default = NA)) - } ### End if(!(elasticity |> is.null())) - ###### By State ###### ### By state byState <- TRUE @@ -369,6 +360,15 @@ extend_slrScalars <- function( df0 <- df0 |> select(-all_of(drop1)) rm(drop0, drop1) + ###### Elasticity ###### + ### Update exponent + if(!(elasticity |> is.null())){ + # df_info <- df_info |> mutate(exp0 = (exp0 == 1) |> ifelse(exp0, elasticity)) + df_info <- df_info |> mutate(exp0 = (econMultiplierName=="vsl_usd") |> ifelse(elasticity, exp0)) + } ### End if(!(elasticity |> is.null())) + ### Add column + df_info <- df_info |> mutate(econAdjName = "none") + ###### Join Data & Scalar Info ###### ### Join initial results & scalar info drop0 <- c("byState") @@ -390,7 +390,7 @@ extend_slrScalars <- function( gather0 <- c("gdp_usd", "gdp_percap") select0 <- gather0 |> c("year") # select0 <- gather0 |> c("byState", "year") - df_mult0 <- df_se |> summarize_seScenario(national=T) + df_mult0 <- df_se |> summarize_seScenario(national=T) df_mult0 <- df_mult0 |> filter(byState==0) df_mult0 <- df_mult0 |> select(all_of(select0)) df_mult0 <- df_mult0 |> pivot_longer(