Title: | Creates SI OHA Mission Director Briefers |
---|---|
Description: | Creates a series of data frames that can be passed to a gt() to create the PEPFAR summary tables. |
Authors: | Tim Essam [aut, cre], Aaron Chafetz [aut], Karishma Srinkanth [aut] |
Maintainer: | Tim Essam <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.4.0 |
Built: | 2025-01-07 05:00:57 UTC |
Source: | https://github.com/USAID-OHA-SI/selfdestructin5 |
Bold columns inside gt objects Helper function to quickly make columns within table bold
bold_column(gt_obj, col, wt = 700)
bold_column(gt_obj, col, wt = 700)
gt_obj |
gt object to be bolded |
col |
column or columns to be bolded |
wt |
weight of boldness can be lighter, normal, bold, or bolder or 0-1000 |
a modified gt object
## Not run: mtcars %>% gt(groupname_col = "cyl") %>% bold_column(c(mpg, hp, drat, carb), wt = "bolder") ## End(Not run)
## Not run: mtcars %>% gt(groupname_col = "cyl") %>% bold_column(c(mpg, hp, drat, carb), wt = "bolder") ## End(Not run)
Make all text larger Bold Agency names - used to increase stroke on row group label
bold_rowgroup(gt_obj, wt = 700)
bold_rowgroup(gt_obj, wt = 700)
gt_obj |
gt object pass through |
wt |
size (0-1000) of embiggening |
a modified gt object
Other gt helpers:
authors_footnote()
,
caveats_footnote()
,
change_footnote()
,
dedup_footnote()
,
delta_footnote()
,
extract_num_colnames()
,
legend
,
legend_q1
,
legend_q2
,
legend_q3
,
legend_snapshot
,
past_fy()
,
present_fy()
,
present_qtr()
,
vlc_footnote()
## Not run: mtcars %>% gt(groupname_col = "cyl") %>% bold_rowgroup(wt = 500) ## End(Not run)
## Not run: mtcars %>% gt(groupname_col = "cyl") %>% bold_rowgroup(wt = 500) ## End(Not run)
Helper function for calculating growth. Returns NA_real_ if the
calc_growth(x, y)
calc_growth(x, y)
x |
numerator to calculate growth - most recent metric |
y |
denominator to calculate growth - lagged metric |
Other MDB helper functions:
format_indicator()
,
label_aggregation()
,
make_achv_shape()
,
make_chg_shape()
## Not run: calc_growth(110, 100) #should give 10% df %>% mutate(z_change = calc_growth(results_cumulative, dplyr::lag(results_cumulative, n = 4))) ## End(Not run)
## Not run: calc_growth(110, 100) #should give 10% df %>% mutate(z_change = calc_growth(results_cumulative, dplyr::lag(results_cumulative, n = 4))) ## End(Not run)
Helper function to collapse data down by a provided grouping. Used in the creation of the main MDB table.
collapse_base_tbl(df, indic_list, ...)
collapse_base_tbl(df, indic_list, ...)
df |
MSD or Genie data frame |
indic_list |
list of indicators to be filter on |
... |
dot-dot-dot that can be passed to the group_by step |
collapse_vlc_tbl to see equivalent collapse sequence for VLC/VLCS variables
Other data frame munging:
collapse_vlc_tbl()
,
make_mdb_df()
,
make_mdb_tx_df()
,
reshape_mdb_df()
,
reshape_mdb_tx_df()
Helper function to collapse data down by a provided grouping. Used in the creation of the treatment / viral load coverage MDB table.
collapse_vlc_tbl(df, ...)
collapse_vlc_tbl(df, ...)
df |
MSD or Genie data frame |
... |
dot-dot-dot to be used in the grouping option |
collapsed data frame of TX_CURR and TX_PVLS indicators
collapse_base_tbl to see equivalent collapse sequence for core indicators.
Other data frame munging:
collapse_base_tbl()
,
make_mdb_df()
,
make_mdb_tx_df()
,
reshape_mdb_df()
,
reshape_mdb_tx_df()
Creates a MDB table for a specified OU or list of OUS. Can be called in a purrr statement for batch creating
create_mdb(df, ou, type = "main", legend = NULL, legend_height = 20)
create_mdb(df, ou, type = "main", legend = NULL, legend_height = 20)
df |
data frame resulting from running |
ou |
operating unit for which table is to be returned |
type |
type of table to be created, main or treatment |
legend |
can pass a legend to subtitle if desired, default is NULL |
legend_height |
adjusts the height of the preset legend |
mdb_gt a gt object formatted as the main or treatment table
## Not run: create_mdb(mdb_tbl, "Global") create_mdb(mdb_tbl_tx, "Zambia", type = "treatment") # Batch produce tables ou_batch <- mdb_tbl_tx %>% filter(agg_type == "OU") %>% distinct(operatingunit) %>% pull() purrr::map(ou_batch, ~create_mdb(mdb_tbl, ou = .x)) # More advanced example selecting single indicator across numerous OUS create_mdb(mdb_tbl_tx %>% filter(indicator == "VLC"), c("Malawi", "Zambia"), type = "treatment") %>% cols_unhide(operatingunit) ## End(Not run)
## Not run: create_mdb(mdb_tbl, "Global") create_mdb(mdb_tbl_tx, "Zambia", type = "treatment") # Batch produce tables ou_batch <- mdb_tbl_tx %>% filter(agg_type == "OU") %>% distinct(operatingunit) %>% pull() purrr::map(ou_batch, ~create_mdb(mdb_tbl, ou = .x)) # More advanced example selecting single indicator across numerous OUS create_mdb(mdb_tbl_tx %>% filter(indicator == "VLC"), c("Malawi", "Zambia"), type = "treatment") %>% cols_unhide(operatingunit) ## End(Not run)
Embiggen parts of mdb table A noble spirit embiggens the smallest man
embiggen(gt_obj, tbl_size = 15, ftnote_size = 10, source_size = 10)
embiggen(gt_obj, tbl_size = 15, ftnote_size = 10, source_size = 10)
gt_obj |
gt object to be embiggened |
tbl_size |
font size for the core table |
ftnote_size |
font size for the footnotes |
source_size |
font size for the source notes |
a modified gt object
## Not run: # embiggen mtcars %>% gt(groupname_col = "cyl") %>% embiggen(tbl_size = 15) # de-embiggen mtcars %>% gt(groupname_col = "cyl") %>% embiggen(tbl_size = 8) ## End(Not run)
## Not run: # embiggen mtcars %>% gt(groupname_col = "cyl") %>% embiggen(tbl_size = 15) # de-embiggen mtcars %>% gt(groupname_col = "cyl") %>% embiggen(tbl_size = 8) ## End(Not run)
This helper function is used to extract the names of all the numeric columns in the TX mdb table. The result is passed to the treatment theme for use in formatting columns.
extract_num_colnames(df)
extract_num_colnames(df)
df |
data frame from the |
vector of column names for all numeric vars
Other gt helpers:
authors_footnote()
,
bold_rowgroup()
,
caveats_footnote()
,
change_footnote()
,
dedup_footnote()
,
delta_footnote()
,
legend
,
legend_q1
,
legend_q2
,
legend_q3
,
legend_snapshot
,
past_fy()
,
present_fy()
,
present_qtr()
,
vlc_footnote()
MDB indicators are stored on google drive. This helper function fetches a desired tab. Used to create filters, sort factor levels, and apply plain labels to indicators.
fetch_indicators(tab = "main")
fetch_indicators(tab = "main")
tab |
which table is being created, main or treatment |
dataframe of indicators
## Not run: fetch_indicators(ou_im, tab = "main") fetch_indicators(ou_im, tab = "treatment") ## End(Not run)
## Not run: fetch_indicators(ou_im, tab = "main") fetch_indicators(ou_im, tab = "treatment") ## End(Not run)
Retrieves the metadata set for the package.
fetch_metadata()
fetch_metadata()
A list containing metadata information.
## Not run: meta <- get_metadata() ## End(Not run)
## Not run: meta <- get_metadata() ## End(Not run)
Formats a string containing the main PEPFAR abbrevation and plain text. The PEPFAR abbreviation is listed first and the plain text in a line below. Used to create the upper portion of the MDB tables.
format_indicator(x)
format_indicator(x)
x |
PEPFAR indicator name as an abbreviation and the full definition |
html formatted string that can be rendered in gt
Other MDB helper functions:
calc_growth()
,
label_aggregation()
,
make_achv_shape()
,
make_chg_shape()
## Not run: format_indicator("HTS_TST Received HIV testing service and results") %>% gt::html() %>% htmltools::html_print() df %>% mutate(indicator2 = format_indicator(indicator2)) ## End(Not run)
## Not run: format_indicator("HTS_TST Received HIV testing service and results") %>% gt::html() %>% htmltools::html_print() df %>% mutate(indicator2 = format_indicator(indicator2)) ## End(Not run)
Labels the level of aggregation using regiona, agency or operating unit Used to apply a filter column to the single data frame returned from table operations
label_aggregation(df, type = "OU")
label_aggregation(df, type = "OU")
df |
MSD or genie data frame that has been ran through collapse_base_tbl() |
type |
Level of aggregation to be labeled |
Other MDB helper functions:
calc_growth()
,
format_indicator()
,
make_achv_shape()
,
make_chg_shape()
This helper object returns the location of the new legend. Use this version The object is passed to a legend_chunk f() that creates md for the legend. This can then be inserted into the subtitle as an image.
legend
legend
An object of class character
of length 1.
Other gt helpers:
authors_footnote()
,
bold_rowgroup()
,
caveats_footnote()
,
change_footnote()
,
dedup_footnote()
,
delta_footnote()
,
extract_num_colnames()
,
legend_q1
,
legend_q2
,
legend_q3
,
legend_snapshot
,
past_fy()
,
present_fy()
,
present_qtr()
,
vlc_footnote()
Use legend instead as quarterly legends are no longer necessary
legend_q1
legend_q1
An object of class character
of length 1.
Other gt helpers:
authors_footnote()
,
bold_rowgroup()
,
caveats_footnote()
,
change_footnote()
,
dedup_footnote()
,
delta_footnote()
,
extract_num_colnames()
,
legend
,
legend_q2
,
legend_q3
,
legend_snapshot
,
past_fy()
,
present_fy()
,
present_qtr()
,
vlc_footnote()
Use legend instead as quarterly legends are no longer necessary
legend_q2
legend_q2
An object of class character
of length 1.
Other gt helpers:
authors_footnote()
,
bold_rowgroup()
,
caveats_footnote()
,
change_footnote()
,
dedup_footnote()
,
delta_footnote()
,
extract_num_colnames()
,
legend
,
legend_q1
,
legend_q3
,
legend_snapshot
,
past_fy()
,
present_fy()
,
present_qtr()
,
vlc_footnote()
Use legend instead as quarterly legends are no longer necessary
legend_q3
legend_q3
An object of class character
of length 1.
Other gt helpers:
authors_footnote()
,
bold_rowgroup()
,
caveats_footnote()
,
change_footnote()
,
dedup_footnote()
,
delta_footnote()
,
extract_num_colnames()
,
legend
,
legend_q1
,
legend_q2
,
legend_snapshot
,
past_fy()
,
present_fy()
,
present_qtr()
,
vlc_footnote()
Use legend instead as quarterly legends are no longer necessary
legend_snapshot
legend_snapshot
An object of class character
of length 1.
Other gt helpers:
authors_footnote()
,
bold_rowgroup()
,
caveats_footnote()
,
change_footnote()
,
dedup_footnote()
,
delta_footnote()
,
extract_num_colnames()
,
legend
,
legend_q1
,
legend_q2
,
legend_q3
,
past_fy()
,
present_fy()
,
present_qtr()
,
vlc_footnote()
Description Function to create and color achievement circles. The circles are placed next to the most recent achievement level in the main MDB table.
make_achv_shape(x)
make_achv_shape(x)
x |
color hex code created by adorn_achievement function |
Returns a html formatting circle that can be embedded in gt object
return gt html() code for an svg
Other MDB helper functions:
calc_growth()
,
format_indicator()
,
label_aggregation()
,
make_chg_shape()
## Not run: achv_circle(glitr::scooter) %>% htmltools::html_print() df %>% mutate(achv_color = achv_circle(achv_color)) ## End(Not run)
## Not run: achv_circle(glitr::scooter) %>% htmltools::html_print() df %>% mutate(achv_color = achv_circle(achv_color)) ## End(Not run)
Creates an svg object based on the direction of change of a performance variable. The svg code can be embedded in a data frame and passed to gt() for prettifying a table. Appears to work well when applied with purrr::map()
make_chg_shape(change_dir)
make_chg_shape(change_dir)
change_dir |
variable indicating direction of change or not applicable |
gt html() code for an svg
Other MDB helper functions:
calc_growth()
,
format_indicator()
,
label_aggregation()
,
make_achv_shape()
## Not run: rank_chg("increase") %>% htmltools::html_print() rank_chg("decrease") %>% htmltools::html_print() df %>% mutate(chg_dir = purrr::map(present_z_direction, rank_chg)) ## End(Not run)
## Not run: rank_chg("increase") %>% htmltools::html_print() rank_chg("decrease") %>% htmltools::html_print() df %>% mutate(chg_dir = purrr::map(present_z_direction, rank_chg)) ## End(Not run)
Makes a single table of core MDB indicators for all OUs, countries and USAID.
Uses fetch_indicators()
to filter indicators and resolves known issues as a default.
Output from this function feeds into reshape_mdb_df()
make_mdb_df(df, resolve_issues = T)
make_mdb_df(df, resolve_issues = T)
df |
data frame from which MDB tables will be constructed for core indicators |
resolve_issues |
logical that fetches troublesome mechs and omits them from df |
data frame
reshape_mdb_df()
to reshape into gt ready data frame;
fetch_indicators()
to filter indicators
Other data frame munging:
collapse_base_tbl()
,
collapse_vlc_tbl()
,
make_mdb_tx_df()
,
reshape_mdb_df()
,
reshape_mdb_tx_df()
## Not run: mdb_df <- make_mdb_df(ou_im, resolve_issues = F) ## End(Not run)
## Not run: mdb_df <- make_mdb_df(ou_im, resolve_issues = F) ## End(Not run)
Uses the collapse_vlc_tbl()
to combine different data frames needed to calculate VLS and VLC.
Filters for mechs with known issues by default, can be controlled with resolve_issues argument.
Wrapper function to create three core tables needed for the treatment MDB data frame.
First, it creates a TX_CURR table and excludes South Africa from the USAID Global table.
Second, collapse_vlc_tbl()
is called to create the VLS/VLC table needed for derived indicators.
Third, Three month + MMD is calculated from the TX_CURR table.
Finally, the tables are combined to be used in creation of the VLS/VLC and MMD+ Share calculations.
make_mdb_tx_df(df, resolve_issues = "TRUE", tx_indic = "TX_CURR")
make_mdb_tx_df(df, resolve_issues = "TRUE", tx_indic = "TX_CURR")
df |
usually and ou_im data frame |
resolve_issues |
logical indicating whether or not known issues are removed |
tx_indic |
TX_CURR is only valid value |
data frame of the combined TX and VLS/VLC indicator
reshape_mdb_tx_df()
used to reshape the resulting output into gt ready data frame;
Other data frame munging:
collapse_base_tbl()
,
collapse_vlc_tbl()
,
make_mdb_df()
,
reshape_mdb_df()
,
reshape_mdb_tx_df()
A gt theme to be applied to a reshaped data frame for the creation of MDB tables. The theme formats all columns and rows for the main MDB tables. A different theme exists for the treatment tables as the layout is different.
mdb_main_theme(df, ...)
mdb_main_theme(df, ...)
df |
|
... |
dot-dot-dot option to pass additional formatting to gt object |
formatted gt object
Other MDB gt themes:
mdb_treatment_theme()
## Not run: mdb_df <- make_mdb_df(ou_im, resolve_issues = F) mdb_tbl <- reshape_mdb_df(mdb_df) mdb_tbl %>% filter(operatingunit == "Zambia") %>% gt(groupname_col = "agency") %>% mdb_main_theme() ## End(Not run)
## Not run: mdb_df <- make_mdb_df(ou_im, resolve_issues = F) mdb_tbl <- reshape_mdb_df(mdb_df) mdb_tbl %>% filter(operatingunit == "Zambia") %>% gt(groupname_col = "agency") %>% mdb_main_theme() ## End(Not run)
This dataset contains information about various indicators related to prevention, testing, and treatment of HIV/AIDS. The dataset includes information on the indicator category, specific indicators, their plain text descriptions, frequency, type, and the table they belong to.
mdb_tbl
mdb_tbl
A data frame with 16 rows and 7 variables:
Indicator category, such as prevention, testing, or treatment.
Short code for the indicator.
Plain text description of the indicator.
Frequency of data collection, either quarterly or semi-annual.
Type of data collected, such as cumulative, snapshot, or derived.
Table the indicator belongs to, either main or treatment.
## Not run: # Example of accessing the dataset data(mdb_tbl) head(mdb_tbl) ## End(Not run)
## Not run: # Example of accessing the dataset data(mdb_tbl) head(mdb_tbl) ## End(Not run)
A gt theme to be applied to a reshaped data frame for the creation of MDB tables. The theme formats all columns and rows for the main MDB tables. A different theme exists for the main tables as the layout is different.
mdb_treatment_theme(df, ...)
mdb_treatment_theme(df, ...)
df |
a dataframe from |
... |
dot-dot-dot option to pass additional formatting to gt object |
formatted gt object
Other MDB gt themes:
mdb_main_theme()
## Not run: mdb_df <- make_mdb_tx_df(ou_im, resolve_issues = F) mdb_tbl <- reshape_mdb_tx_df(mdb_df) numeric_cols <- mdb_tbl %>% select_if(is.numeric) %>% names() mdb_tbl %>% filter(operatingunit == "Zambia") %>% gt(groupname_col = "agency") %>% mdb_treatment_theme(numeric_cols) ## End(Not run)
## Not run: mdb_df <- make_mdb_tx_df(ou_im, resolve_issues = F) mdb_tbl <- reshape_mdb_tx_df(mdb_df) numeric_cols <- mdb_tbl %>% select_if(is.numeric) %>% names() mdb_tbl %>% filter(operatingunit == "Zambia") %>% gt(groupname_col = "agency") %>% mdb_treatment_theme(numeric_cols) ## End(Not run)
requires having si_path setup from glamr
msd_period(type = "OU_IM", period = NULL)
msd_period(type = "OU_IM", period = NULL)
type |
Type of MSD (OU_IM, PSNU, PSNU_IM, NAT_SUBNAT) |
period |
can provide period from ICPIutilities::identifypd(), or it will run if NULL |
FY00Q0t MSD
reshape_mdb_df
takes the output from make_mdb_df()
and creates a gt ready data frame.
The transformed data frame retains the most recent quarter and previous year's performance.
The resulting table can be passed directly to the mdb_main_theme()
to create a MDB table.
Helper functions format certain columns as svgs to be rendered in the gt call.
reshape_mdb_df(df)
reshape_mdb_df(df)
df |
takes the |
returns a wide formatted data frame (table) of all OUs, countries and USAID
make_mdb_df()
to see input required and
mdb_main_theme()
to see the gt theme used to format the table
make_chg_shape()
creates an svg based on the direction of change
make_achv_shape()
creates a colored circle based on achievement level
Other data frame munging:
collapse_base_tbl()
,
collapse_vlc_tbl()
,
make_mdb_df()
,
make_mdb_tx_df()
,
reshape_mdb_tx_df()
## Not run: mdb_df <- make_mdb_df(ou_im, resolve_issues = F) mdb_tbl <- reshape_mdb_df(mdb_df) ## End(Not run)
## Not run: mdb_df <- make_mdb_df(ou_im, resolve_issues = F) mdb_tbl <- reshape_mdb_df(mdb_df) ## End(Not run)
reshape_mdb_tx_df
takes the output from make_mdb_tx_df()
and creates a gt ready data frame.
The transformed data frame retains the most recent quarter and previous year performance.
Viral load coverage and viral load suppression percentages are calculated along with TX MMD shares.
The resulting table can be passed directly to the mdb_treatment_theme()
to create a MDB table.
Helper functions format certain columns as svgs to be rendered in the gt call.
reshape_mdb_tx_df(df)
reshape_mdb_tx_df(df)
df |
dataframe that is the result of running make_mdb_tx_df() |
Create a wide formatted and sorted table for treatment indicators
data frame that is pivoted wide for passing to gt() call
Other data frame munging:
collapse_base_tbl()
,
collapse_vlc_tbl()
,
make_mdb_df()
,
make_mdb_tx_df()
,
reshape_mdb_df()
## Not run: mdb_df <- make_mdb_tx_df(ou_im, resolve_issues = F) mdb_tbl <- reshape_mdb_tx_df(mdb_df) ## End(Not run)
## Not run: mdb_df <- make_mdb_tx_df(ou_im, resolve_issues = F) mdb_tbl <- reshape_mdb_tx_df(mdb_df) ## End(Not run)
Sets the metadata for the package, which can be used across various functions.
set_metadata(meta)
set_metadata(meta)
meta |
A list containing metadata information. |
## Not run: metadata <- gophr::get_metadata(file_path) set_metadata(metadata) ## End(Not run)
## Not run: metadata <- gophr::get_metadata(file_path) set_metadata(metadata) ## End(Not run)