Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

State code initial #56

Closed
wants to merge 11 commits into from
2 changes: 2 additions & 0 deletions R/createSystemData.R
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ createSystemData <- function(
byState = byState
) ### End fun_formatScalars
### Add other info
update_popScalars <- utils::getFromNamespace("update_popScalars", "FrEDI")
df_mainScalars <- df_mainScalars |> update_popScalars(df_national)
### Update list
rDataList[["df_mainScalars"]] <- df_mainScalars
Expand All @@ -218,6 +219,7 @@ createSystemData <- function(
data_scaledImpacts <- data_scaledImpacts |> get_scenario_id(include=includeCols)
### Get list of scenarios for scenarios with at least some non-NA values
c_scenariosList <- data_scaledImpacts |> filter(!(scaledImpact |> is.na()))
get_uniqueValues <- utils::getFromNamespace("get_uniqueValues", "FrEDI")
c_scenariosList <- c_scenariosList |> get_uniqueValues(column="scenario_id")
### Add information on non-missing scenarios to scaled impacts data
data_scaledImpacts <- data_scaledImpacts |> mutate(hasScenario = (scenario_id %in% c_scenariosList))
Expand Down
74 changes: 74 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ fun_formatScalars <- function(
if(byState){states_i <- data_i[["state"]] |> unique()} else{states_i <- "N/A"}
byState_i <- !("N/A" %in% states_i) & byState
### Interpolate data
interpolate_annual <- utils::getFromNamespace("interpolate_annual" , "FrEDI")
data_i <- data_i |> interpolate_annual(
years = years_x,
column = "value",
Expand Down Expand Up @@ -372,3 +373,76 @@ get_impactFunctions <- function(
return(list_x)
}

###### fun_slrModel2Height ######
### Helper function to convert SLR model to height in cm
fun_slrModel2Height <- function(
col_x, ### column "model_dot"
include = c("factor", "values"),
valType = c("numeric", "character", "factor"),
labelType = c("numeric", "character") ### Used for factor or label

){
### Checks
do_factor <- "factor" %in% include
do_values <- "values" %in% include
do_both <- do_factor & do_values
### Value types and priority
valTypes <- c("numeric", "character", "factor")
valType0 <- valType
valType0 <- valTypes |> (function(y, types_y=valTypes){
ls1 <- ls0 <- types_y
c0 <- ls0[1] %in% y
c1 <- ls0[2] %in% y
c3 <- ls0[2] %in% y
if(c0) {ls1 <- ls0[1]}
else if(c1) {ls1 <- ls0[2]}
else {ls1 <- ls0[3]}
return(ls1)
})()
do_numb <- "numeric" %in% valType
do_char <- "character" %in% valType
do_fact <- "factor" %in% valType
# valType |> print(); labelType |> print()
### Label types and priority
labTypes <- c("numeric", "character")
label_x0 <- labelType |>
(function(y, types_y=labTypes){
ls1 <- ls0 <- types_y
c0 <- do_numb | do_char
c1 <- ls0[1] %in% y
if(c0) {ls1 <- ls0[1]}
else if(c1) {ls1 <- ls0[1]}
else {ls1 <- ls0[2]}
return(ls1)
})()
# label_x0 |> print()
labChar <- "character" %in% label_x0
# label_x0 |> print(); labChar |> print()
### Original labels
lvl_x0 <- col_x |> unique()
df_x0 <- tibble(levels=lvl_x0)
### Standardize
df_x0$labels <- gsub("_" , "", df_x0$levels)
df_x0$numbers <- gsub("cm", "", df_x0$labels)
df_x0$values <- df_x0$numbers |> as.character() |> as.numeric()
### Sprt
df_x0 <- df_x0 |> arrange_at(.vars=c("values"))
### Create factor list
list_x <- list(factors=df_x0)
### Adjust values
vals_x <- NULL
if(do_values){
if(labChar){labels_x <- df_x0$labels}
else {labels_x <- df_x0$values}
vals_x <- col_x |> factor(levels=df_x0$levels, labels=labels_x)
if(do_char){vals_x <- vals_x |> as.character()}
if(do_numb){vals_x <- vals_x |> as.numeric()}
list_x[["values"]] <- vals_x
}
### Return list
if (do_both ) {return_x <- list_x}
else if(do_factor) {return_x <- list_x$factors}
else {return_x <- list_x$values}
### Return
return(return_x)
}
Binary file modified data/tmp_sysdata.rda
Binary file not shown.
Binary file modified inst/extdata/FrEDI_config.xlsx
Binary file not shown.
2,157 changes: 0 additions & 2,157 deletions inst/extdata/state/gcm/AirQuality_scaledimpacts.csv

This file was deleted.

721 changes: 0 additions & 721 deletions inst/extdata/state/gcm/AsphaltRoads_scaledimpacts.csv

This file was deleted.

4,558 changes: 0 additions & 4,558 deletions inst/extdata/state/gcm/ElecTD_scaledimpacts.csv

This file was deleted.

4,558 changes: 0 additions & 4,558 deletions inst/extdata/state/gcm/Rail_scaledimpacts.csv

This file was deleted.

4,558 changes: 0 additions & 4,558 deletions inst/extdata/state/gcm/Roads_scaledimpacts.csv

This file was deleted.

501 changes: 0 additions & 501 deletions inst/extdata/state/gcm/WindDamage_scaledimpacts.csv

This file was deleted.

4,607 changes: 0 additions & 4,607 deletions inst/extdata/state/scalars/Scalar_damageAdj_elecTD_growthFactor.csv

This file was deleted.

21 changes: 0 additions & 21 deletions inst/extdata/state/scalars/Scalar_damageAdj_rail_growth_factor.csv

This file was deleted.

Loading