Skip to content

Commit

Permalink
package update 2.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
abhimishr committed Nov 9, 2023
1 parent d1fbe48 commit f238691
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 40 deletions.
3 changes: 2 additions & 1 deletion .lintr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ linters: linters_with_defaults(
cyclocomp_linter(25),
brace_linter=NULL,
line_length_linter(250),
object_usage_linter = NULL
object_usage_linter = NULL,
indentation_linter = NULL
) # see vignette("lintr")
encoding: "UTF-8"
63 changes: 30 additions & 33 deletions R/appIMPACT.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ appIMPACT <- function(folder, base_year = NULL) {

sidebarPanel(

selectInput(inputId = "indicator", label = strong("Indicator"),
selectInput(inputId = "s_indicator", label = strong("Indicator"),
choices = unique(df_prep$indicator),
selected = "Population"),

selectInput(inputId = "region", "Regions",
selectInput(inputId = "s_region", "Regions",
choices = unique(df_prep$region),
multiple = TRUE,
selected = unique(df_prep$region)),

sliderInput(inputId = "year", label = strong("Year"),
sliderInput(inputId = "s_year", label = strong("Year"),
min = min(df_prep$yrs),
value = c(min(df_prep$yrs), max(df_prep$yrs)),
max = max(df_prep$yrs),
Expand All @@ -79,12 +79,12 @@ appIMPACT <- function(folder, base_year = NULL) {
width = NULL))
),

selectInput(inputId = "flag", label = strong("Scenarios"),
selectInput(inputId = "s_flag", label = strong("Scenarios"),
choices = unique(df_prep$flag),
multiple = TRUE,
selected = unique(df_prep$flag)),

selectInput(inputId = "base_run", label = strong("BASE run"),
selectInput(inputId = "s_base_run", label = strong("BASE run"),
choices = c("", unique(df_prep$flag)),
selected = NULL,
multiple = FALSE),
Expand Down Expand Up @@ -137,29 +137,27 @@ appIMPACT <- function(folder, base_year = NULL) {
class(df_prep) <- "data.frame"

df_prep %>%
filter(indicator == input$indicator) %>%
filter(region %in% input$region) %>%
filter(flag %in% input$flag) %>%
filter(yrs %in% c(input$year[1]:input$year[2])) %>%
filter(indicator == input$s_indicator) %>%
filter(region %in% input$s_region) %>%
filter(flag %in% input$s_flag) %>%
filter(yrs %in% c(input$s_year[1]:input$s_year[2])) %>%
filter(unit2 %in% case_when(input$line_plot_type == "None" ~ unique(grep("wrt", unit2, value = TRUE, invert = TRUE)),
input$line_plot_type == "Relative" ~ unique(grep("wrt", unique(grep("Index|Default", unit2, value = TRUE, invert = TRUE)), value = TRUE)),
input$line_plot_type == "Index" ~ unique(grep("Index", unit2, value = TRUE))
)
input$line_plot_type == "Index" ~ unique(grep("Index", unit2, value = TRUE)))
)
})

dfx_bar <- reactive({
class(df_prep) <- "data.frame"

df_prep %>%
filter(indicator == input$indicator) %>%
filter(region %in% setdiff(input$region, "GLO")) %>%
filter(flag %in% input$flag) %>%
filter(yrs %in% c(input$year[1]:input$year[2])) %>%
filter(indicator == input$s_indicator) %>%
filter(region %in% setdiff(input$s_region, "GLO")) %>%
filter(flag %in% input$s_flag) %>%
filter(yrs %in% c(input$s_year[1]:input$s_year[2])) %>%
filter(unit2 %in% case_when(input$line_plot_type == "None" ~ unique(grep("wrt", unit2, value = TRUE, invert = TRUE)),
input$line_plot_type == "Relative" ~ unique(grep("wrt", unique(grep("Index|Default", unit2, value = TRUE, invert = TRUE)), value = TRUE)),
input$line_plot_type == "Index" ~ unique(grep("Index", unit2, value = TRUE))
)
input$line_plot_type == "Index" ~ unique(grep("Index", unit2, value = TRUE)))
)
})

Expand Down Expand Up @@ -219,38 +217,37 @@ appIMPACT <- function(folder, base_year = NULL) {
output$compare_df <- DT::renderDataTable({

DT::datatable(df_prep[, c("model", "region", "yrs", "indicator", "value", "unit", " unit2", "flag")] %>%
filter(indicator == input$indicator) %>%
filter(region %in% input$region) %>%
filter(flag %in% input$flag) %>%
filter(yrs %in% c(input$year[1]:input$year[2])) %>%
filter(indicator == input$s_indicator) %>%
filter(region %in% input$s_region) %>%
filter(flag %in% input$s_flag) %>%
filter(yrs %in% c(input$s_year[1]:input$s_year[2])) %>%
filter(unit2 %in% case_when(input$line_plot_type == "None" ~ unique(grep("wrt", unit2, value = TRUE, invert = TRUE)),
input$line_plot_type == "Relative" ~ unique(grep("wrt", unique(grep("Index|Default", unit2, value = TRUE, invert = TRUE)), value = TRUE)),
input$line_plot_type == "Index" ~ unique(grep("Index", unit2, value = TRUE))
)
input$line_plot_type == "Index" ~ unique(grep("Index", unit2, value = TRUE)))
) %>%
group_by(across(c("model", "region", "indicator", "unit", "unit2", "yrs"))) %>%
mutate(delta_base_RUN = case_when(!is.null(input$base_run) ~ paste0(round(100 * ((value / value[flag == input$base_run]) - 1), 2), "%"),
input$base_run == "" ~ paste0("Select base run"))
mutate(delta_base_RUN = case_when(!is.null(input$s_base_run) ~ paste0(round(100 * ((value / value[flag == input$s_base_run]) - 1), 2), "%"),
input$s_base_run == "" ~ paste0("Select base run"))
) %>%
filter(case_when(!is.null(input$base_run) ~ flag %in% setdiff(unique(df_prep$flag), input$base_run))) %>%
filter(yrs == input$year[2]) %>%
filter(case_when(!is.null(input$s_base_run) ~ flag %in% setdiff(unique(df_prep$flag), input$s_base_run))) %>%
filter(yrs == input$s_year[2]) %>%
mutate(value = round(value, 2))
)
})

output$compare_df_year <- DT::renderDataTable({
DT::datatable(df_prep[, c("model", "region", "yrs", "indicator", "value", "unit", "unit2", "flag")] %>%
filter(indicator == input$indicator) %>%
filter(region %in% input$region) %>%
filter(flag %in% input$flag) %>%
filter(yrs %in% c(input$year[1]:input$year[2])) %>%
filter(indicator == input$s_indicator) %>%
filter(region %in% input$s_region) %>%
filter(flag %in% input$s_flag) %>%
filter(yrs %in% c(input$s_year[1]:input$s_year[2])) %>%
filter(unit2 %in% case_when(input$line_plot_type == "None" ~ unique(grep("wrt", unit2, value = TRUE, invert = TRUE)),
input$line_plot_type == "Relative" ~ unique(grep("wrt", unique(grep("Index|Default", unit2, value = TRUE, invert = TRUE)), value = TRUE)),
input$line_plot_type == "Index" ~ unique(grep("Index", unit2, value = TRUE)))
) %>%
group_by(across(c("model", "region", "indicator", "unit", "unit2", "flag"))) %>%
mutate(delta_base_YEAR = paste0(round(100 * ((value / value[yrs == input$year[1]]) - 1), 2), "%")) %>%
filter(yrs == input$year[2]) %>%
mutate(delta_base_YEAR = paste0(round(100 * ((value / value[yrs == input$s_year[1]]) - 1), 2), "%")) %>%
filter(yrs == input$s_year[2]) %>%
mutate(value = round(value, 2))
)
})
Expand Down
14 changes: 8 additions & 6 deletions R/rdsMaker.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#' @export
rdsMaker <- function(folder, base_year = NULL) {

files <- grep(pattern = ".gdx",
files <- grep(pattern = "\\.gdx",
x = list.files(path = folder),
value = TRUE)

Expand All @@ -26,7 +26,7 @@ rdsMaker <- function(folder, base_year = NULL) {
skip_msg <- FALSE

for (file_vector in paste0(folder, "/", choice)) {
file_exists <- file.exists(gsub(pattern = ".gdx",
file_exists <- file.exists(gsub(pattern = "\\.gdx",
replacement = ".rds",
x = (file_vector)))
if (file_exists) {
Expand All @@ -50,19 +50,21 @@ rdsMaker <- function(folder, base_year = NULL) {
skip_next_choice <- TRUE
cat("Attempting to convert to RDS file ......", "\n")
if (is.null(base_year)) getReport(gdx = file_vector,
prep_flag = prep_flag)
prep_flag = prep_flag,
relative_calc = TRUE)
if (!is.null(base_year)) getReport(gdx = file_vector,
prep_flag = prep_flag,
base_year = base_year)
base_year = base_year,
relative_calc = TRUE)
choice[choice == basename(file_vector)] <-
gsub(pattern = ".gdx",
gsub(pattern = "\\.gdx",
replacement = ".rds",
x = basename(file_vector))
user_choice <- 1
}

choice[choice == basename(file_vector)] <-
gsub(pattern = ".gdx",
gsub(pattern = "\\.gdx",
replacement = ".rds",
x = basename(file_vector))

Expand Down

0 comments on commit f238691

Please sign in to comment.