Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ Remotes:
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.2
RoxygenNote: 7.2.1
Config/testthat/edition: 3
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export("%>%")
export(export_all_countries_summaries_xls)
export(export_country_summary_xls)
export(export_plot_timeseries_indicator_pdf)
export(export_regional_data)
export(plot_timeseries_indicator)
importFrom(magrittr,"%>%")
importFrom(rlang,"!!")
Expand Down
92 changes: 74 additions & 18 deletions R/export_country_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,9 @@ export_country_summary_xls <- function(df,
)
}

sheets_hidden <- grep("_Inter$", openxlsx::sheets(wb))
for (i in sheets_hidden) {
openxlsx::sheetVisibility(wb)[sheets_hidden] <- "hidden"
}
# Remove Chart and Inter sheets
purrr::walk(openxlsx::sheets(wb)[stringr::str_detect(openxlsx::sheets(wb), "_Chart$|_Inter$")], ~ openxlsx::removeWorksheet(wb, .x))


# Write workbook
if (!dir.exists(output_folder)) {
Expand Down Expand Up @@ -327,6 +326,7 @@ export_hep_country_summary_xls <- function(df,
# summary sheet
summary_sheet <- glue::glue("{sheet_prefix}_summary")


wb <- write_hep_summary_sheet(
df = df_iso_one_scenario,
wb = wb,
Expand All @@ -341,6 +341,9 @@ export_hep_country_summary_xls <- function(df,
ind_ids
)

openxlsx::groupRows(wb, sheet = summary_sheet, rows = 35:37, hidden = TRUE)


write_hep_timeseries_sheet(
df = df_iso_one_scenario,
wb = wb,
Expand All @@ -354,8 +357,12 @@ export_hep_country_summary_xls <- function(df,

if(!is.null(scenario_col)){
if(length(unique(df_iso[[scenario_col]])) > 1){

df_iso_no_base_scenarios <- df_iso %>%
dplyr::filter(.data[[scenario_col]] %in% scenarios_not_base)

write_scenario_sheet(
df = df_iso,
df = df_iso_no_base_scenarios,
wb = wb,
billion = "hep",
sheet_name = glue::glue("{sheet_prefix}_Scenarios"),
Expand All @@ -372,6 +379,20 @@ export_hep_country_summary_xls <- function(df,
}
}

# Plot
plot_sheet <- glue::glue("{sheet_prefix}_Plot")

write_plot_sheet(
df = df_iso_one_scenario,
wb = wb,
sheet_name = plot_sheet,
billion = "hep",
start_year = start_year,
end_year = end_year,
ind_df = ind_df,
ind_ids = ind_ids
)

openxlsx::addStyle(wb,
sheet = "HEP_Chart", rows = 22, cols = (3:(2 + nrow(ind_df))),
style = excel_styles(
Expand Down Expand Up @@ -523,8 +544,12 @@ export_hpop_country_summary_xls <- function(df,
)

if(length(unique(df_iso[[scenario_col]])) > 1){

df_iso_no_base_scenarios <- df_iso %>%
dplyr::filter(.data[[scenario_col]] %in% scenarios_not_base)

write_scenario_sheet(
df = df_iso,
df = df_iso_no_base_scenarios,
wb = wb,
billion = "hpop",
sheet_name = glue::glue("{sheet_prefix}_Scenarios"),
Expand All @@ -540,19 +565,32 @@ export_hpop_country_summary_xls <- function(df,
)
}

# Plot
plot_sheet <- glue::glue("{sheet_prefix}_Plot")

# Flip titles graph
openxlsx::addStyle(wb,
sheet = "HPOP_Chart", rows = 22, cols = (3:(2 + nrow(ind_df))),
style = excel_styles(
textRotation = 90,
fontSize = 8,
fgFill = "white",
wrapText = TRUE,
halign = "center",
valign = "center"
)
write_plot_sheet(
df = df_iso_one_scenario,
wb = wb,
sheet_name = plot_sheet,
billion = "hpop",
start_year = start_year,
end_year = end_year,
ind_df = ind_df,
ind_ids = ind_ids
)

# Flip titles graph
# openxlsx::addStyle(wb,
# sheet = "HPOP_Chart", rows = 22, cols = (3:(2 + nrow(ind_df))),
# style = excel_styles(
# textRotation = 90,
# fontSize = 8,
# fgFill = "white",
# wrapText = TRUE,
# halign = "center",
# valign = "center"
# )
# )
return(wb)
}

Expand Down Expand Up @@ -657,8 +695,12 @@ export_uhc_country_summary_xls <- function(df,
)

if(length(unique(df_iso[[scenario_col]])) > 1){

df_iso_no_base_scenarios <- df_iso %>%
dplyr::filter(.data[[scenario_col]] %in% scenarios_not_base)

write_scenario_sheet(
df = df_iso,
df = df_iso_no_base_scenarios,
wb = wb,
billion = "uhc",
sheet_name = glue::glue("{sheet_prefix}_Scenarios"),
Expand All @@ -674,6 +716,20 @@ export_uhc_country_summary_xls <- function(df,
)
}

# Plot
plot_sheet <- glue::glue("{sheet_prefix}_Plot")

write_plot_sheet(
df = df_iso_one_scenario,
wb = wb,
sheet_name = plot_sheet,
billion = "uhc",
start_year = start_year,
end_year = end_year,
ind_df = ind_df,
ind_ids = ind_ids
)

openxlsx::addStyle(wb,
sheet = "UHC_Chart", rows = 22, cols = (3:(2 + nrow(ind_df))),
style = excel_styles(
Expand Down
Loading