Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/initial_actions_kmn' into init…
Browse files Browse the repository at this point in the history
…ial_actions

Updating initial actions branch
  • Loading branch information
tonygard-indecon committed Sep 19, 2023
2 parents 03fe978 + 09d1f21 commit 7aa5b0e
Show file tree
Hide file tree
Showing 14 changed files with 104 additions and 301 deletions.
Binary file removed R/configLog/fredi_config_20230919.rda
Binary file not shown.
8 changes: 4 additions & 4 deletions R/configTests.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

require(tidyverse)
###### Dimension Tests ######
#' test_loadData
#'
Expand Down Expand Up @@ -129,7 +129,7 @@ general_config_test <- function(
configuredData = NULL, ### List of configured data
# reshapedFile = "." %>% file.path("data_tests", "reshapedData_testResults.csv"), ### File name of reshaped data test
outPath = ".",
xlsxName = "testResults_general_config.xlsx",
xlsxName = "generalConfig_testResults.xlsx",
save = TRUE,
return = TRUE,
overwrite = TRUE, ### Whether to overwrite an existing file,
Expand Down Expand Up @@ -363,11 +363,11 @@ general_config_test <- function(
#'
#' @examples
newSectors_config_test <- function(
newData = NULL,
newData = NULL,
refDataFile = "." %>% file.path("data", "sysdata.rda"),
# sector_id = "",
outPath = ".",
xslxName = "testResults_newSectors_config.xlsx",
xslxName = "newSectorsConfig_testResults.xlsx",
save = T,
return = T,
overwrite = T
Expand Down
20 changes: 10 additions & 10 deletions R/createSystemData.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,17 @@ createSystemData <- function(

### Calculate national population and add to data list
df_national <- pop_default %>%
group_by_at(.vars=c(all_of(group0))) %>%
summarize_at(.vars=c(all_of(sum0)), sum, na.rm=T) %>% ungroup
df_national <- df_national %>% rename_at(.vars=c(all_of(sum0)), ~c("national_pop"))
group_by_at(.vars=c(group0)) %>%
summarize_at(.vars=c(sum0), sum, na.rm=T) %>% ungroup
df_national <- df_national %>% rename_at(.vars=c(sum0), ~c("national_pop"))
rDataList[["national_pop_default"]] <- df_national
# df_national %>% names %>% print

### Default scenario: Join national GDP with national population by year
### Default scenario: Join national values with regional population by year
### Calculate GDP per capita and add to list
df_national <- gdp_default %>% left_join(df_national, by=c(all_of(group0)))
df_national <- df_national %>% left_join(pop_default, by=c(all_of(group0)))
df_national <- gdp_default %>% left_join(df_national, by=c(group0))
df_national <- df_national %>% left_join(pop_default, by=c(group0))
df_national <- df_national %>% mutate(gdp_percap = gdp_usd / national_pop)
rDataList[["df_defaultScenario"]] <- df_national
# df_defaultScenario %>% names %>% print
Expand All @@ -152,11 +152,11 @@ createSystemData <- function(
mutate0 <- c("model_type")
string0 <- c("slr")
### Replace NA values
slr_cm <- slr_cm %>% mutate_at(.vars = c(all_of(mutate0)), replace_na, string0)
slrImpacts <- slrImpacts %>% mutate_at(.vars = c(all_of(mutate0)), replace_na, string0)
slr_cm <- slr_cm %>% mutate_at(.vars = c(mutate0), replace_na, string0)
slrImpacts <- slrImpacts %>% mutate_at(.vars = c(mutate0), replace_na, string0)
### Convert to character
slr_cm <- slr_cm %>% mutate_at(.vars = c(all_of(mutate0)), as.character)
slrImpacts <- slrImpacts %>% mutate_at(.vars = c(all_of(mutate0)), as.character)
slr_cm <- slr_cm %>% mutate_at(.vars = c(mutate0), as.character)
slrImpacts <- slrImpacts %>% mutate_at(.vars = c(mutate0), as.character)
### Create data for extreme values above 250cm
slrExtremes <- fun_slrConfigExtremes(
slr_x = slr_cm, ### rDataList$slr_cm
Expand Down Expand Up @@ -195,7 +195,7 @@ createSystemData <- function(
join0 <- c("joinCol")
df_sectorsInfo <- df_sectorsInfo %>% mutate(joinCol=1)
df_national <- df_national %>% mutate(joinCol=1)
df_results0 <- df_sectorsInfo %>% left_join(df_national, by=c(all_of(join0)))
df_results0 <- df_sectorsInfo %>% left_join(df_national, by=c(join0), relationship = "many-to-many")
df_results0 <- df_results0 %>% select(-c(all_of(join0)))
rm("join0"); rm("df_sectorsInfo", "df_national")

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion R/loadData.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ loadData <- function(
### Filter to those for importing and replace NA values in some columns
mutate0 <- c("excludeCol_ids", "Notes")
df_tableNames <- df_tableNames %>% filter(Import == 1)
df_tableNames <- df_tableNames %>% mutate_at(.vars = c(all_of(mutate0)), replace_na, "")
df_tableNames <- df_tableNames %>% mutate_at(.vars = c(mutate0), replace_na, "")
rm("mutate0")

### Number of data tables
Expand Down
95 changes: 0 additions & 95 deletions R/outputTests.R

This file was deleted.

18 changes: 9 additions & 9 deletions R/reshapeData.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ reshapeData <- function(
co_impactYears <- co_impactYears %>% gather(key = "impactYear_label", value = "impactYear2", -c(all_of(drop0)))
co_impactYears <- co_impactYears %>% filter(!is.na(impactYear2))
co_impactYears <- co_impactYears %>% select(-c(all_of(drop1)))
co_impactYears <- co_impactYears %>% left_join(co_impactYearLevels, by = c(all_of(join0)))
co_impactYears <- co_impactYears %>% left_join(co_impactYearLevels, by = c(join0))
# co_impactYears %>% glimpse
### Update/add tables in list
dataList[["co_impactYears" ]] <- co_impactYears
Expand All @@ -78,7 +78,7 @@ reshapeData <- function(
### Remove intermediate variables
join0 <- c("modelType")
co_modelTypes2 <- co_modelTypes %>% rename(modelType = modelType_id)
co_models <- co_models %>% left_join(co_modelTypes2, by = c(all_of(join0))) # ; co_models %>% glimpse
co_models <- co_models %>% left_join(co_modelTypes2, by = c(join0)) # ; co_models %>% glimpse
dataList[["co_models"]] <- co_models
rm("join0", "co_modelTypes2")

Expand All @@ -96,13 +96,13 @@ reshapeData <- function(
drop2 <- c("impactType_id_excel", "impactType_label", "impactType_description")
join0 <- c("sector_id")
rename0 <- c("sector", "variant", "impactYear", "impactType") %>% paste("id", sep = "_")
rename1 <- gsub("_id", "", c(all_of(rename0)))
rename1 <- gsub("_id", "", c(rename0))
### Join with co_impactYears, co_impactTypes
df_sectorsInfo <- co_sectors %>% left_join(co_variants %>% select(-c(all_of(drop0))), by = c(all_of(join0)))
df_sectorsInfo <- df_sectorsInfo %>% left_join(co_impactYears %>% select(-c(all_of(drop1))), by = c(all_of(join0)))
df_sectorsInfo <- df_sectorsInfo %>% left_join(co_impactTypes %>% select(-c(all_of(drop2))), by = c(all_of(join0)))
df_sectorsInfo <- co_sectors %>% left_join(co_variants %>% select(-c(all_of(drop0))), by = c(join0))
df_sectorsInfo <- df_sectorsInfo %>% left_join(co_impactYears %>% select(-c(all_of(drop1))), by = c(join0), relationship = "many-to-many")
df_sectorsInfo <- df_sectorsInfo %>% left_join(co_impactTypes %>% select(-c(all_of(drop2))), by = c(join0), relationship = "many-to-many")
### Rename
df_sectorsInfo <- df_sectorsInfo %>% rename_at(.vars = c(all_of(rename0)), ~ all_of(rename1)) # ; df_sectorsInfo %>% glimpse
df_sectorsInfo <- df_sectorsInfo %>% rename_at(.vars = c(rename0), ~ rename1) # ; df_sectorsInfo %>% glimpse
### Update in list
dataList[["df_sectorsInfo"]] <- df_sectorsInfo
### Remove intermediate variables
Expand Down Expand Up @@ -177,7 +177,7 @@ reshapeData <- function(
### Check impacts
"nrow(c_regSlr) == nrow(slrImpacts)" %>% paste0(": ", nrow(c_regSlr) == nrow(slrImpacts)) %>% print()
### Join and drop join columns
slrImpacts <- slrImpacts %>% left_join(c_regSlr, by = c(all_of(join0)))
slrImpacts <- slrImpacts %>% left_join(c_regSlr, by = c(join0))
slrImpacts <- slrImpacts %>% select(-c(all_of(join0), all_of(select0)))
### Drop intermediate values (update in list further down)
rm("idCols0", "select0", "names0", "join0", "c_regSlr")
Expand Down Expand Up @@ -233,7 +233,7 @@ reshapeData <- function(
df_i <- df_i %>% mutate(model_type = model_dot %>% factor(levels1, labels1))
### Convert to character
mutate0 <- c("variant", "impactYear", "impactType", "model_dot")
df_i <- df_i %>% mutate_at(.vars = c(all_of(mutate0)), as.character)
df_i <- df_i %>% mutate_at(.vars = c(mutate0), as.character)
# rm("levels0", "labels0", "doDot0", "mutate0")
return(df_i)
}) %>%
Expand Down
Loading

0 comments on commit 7aa5b0e

Please sign in to comment.