Package 'selfdestructin5'

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

Help Index


Bold columns inside gt objects Helper function to quickly make columns within table bold

Description

Bold columns inside gt objects Helper function to quickly make columns within table bold

Usage

bold_column(gt_obj, col, wt = 700)

Arguments

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

Value

a modified gt object

Examples

## 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

Description

Make all text larger Bold Agency names - used to increase stroke on row group label

Usage

bold_rowgroup(gt_obj, wt = 700)

Arguments

gt_obj

gt object pass through

wt

size (0-1000) of embiggening

Value

a modified gt object

See Also

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()

Examples

## Not run: 
 mtcars %>% gt(groupname_col = "cyl") %>% bold_rowgroup(wt = 500)
 
## End(Not run)

Calculate growth between two metrics that are positive

Description

Helper function for calculating growth. Returns NA_real_ if the

Usage

calc_growth(x, y)

Arguments

x

numerator to calculate growth - most recent metric

y

denominator to calculate growth - lagged metric

See Also

Other MDB helper functions: format_indicator(), label_aggregation(), make_achv_shape(), make_chg_shape()

Examples

## 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)

Collapse base MSD down to a desired level for main MDB table

Description

Helper function to collapse data down by a provided grouping. Used in the creation of the main MDB table.

Usage

collapse_base_tbl(df, indic_list, ...)

Arguments

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

See Also

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()


Collapse base MSD down to a desired level for core treatment indicators

Description

Helper function to collapse data down by a provided grouping. Used in the creation of the treatment / viral load coverage MDB table.

Usage

collapse_vlc_tbl(df, ...)

Arguments

df

MSD or Genie data frame

...

dot-dot-dot to be used in the grouping option

Value

collapsed data frame of TX_CURR and TX_PVLS indicators

See Also

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()


Wrapper function to create a MDB table

Description

Creates a MDB table for a specified OU or list of OUS. Can be called in a purrr statement for batch creating

Usage

create_mdb(df, ou, type = "main", legend = NULL, legend_height = 20)

Arguments

df

data frame resulting from running reshape_mdb_df() or reshape_mdb_tx_df()

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

Value

mdb_gt a gt object formatted as the main or treatment table

Examples

## 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

Description

Embiggen parts of mdb table A noble spirit embiggens the smallest man

Usage

embiggen(gt_obj, tbl_size = 15, ftnote_size = 10, source_size = 10)

Arguments

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

Value

a modified gt object

Examples

## 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)

Extract a vector of numeric column names

Description

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.

Usage

extract_num_colnames(df)

Arguments

df

data frame from the reshape_mdb_tx_df() call

Value

vector of column names for all numeric vars

See Also

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()


Fetches indicators used to make tables, accounting for quarter of MSD and semi-annual indicators

Description

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.

Usage

fetch_indicators(tab = "main")

Arguments

tab

which table is being created, main or treatment

Value

dataframe of indicators

Examples

## Not run: 
 fetch_indicators(ou_im, tab = "main")
 fetch_indicators(ou_im, tab = "treatment")
## End(Not run)

Fetch metadata

Description

Retrieves the metadata set for the package.

Usage

fetch_metadata()

Value

A list containing metadata information.

Examples

## Not run: 
 meta <- get_metadata()

## End(Not run)

Formats PEPFAR indicators for MDB tables

Description

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.

Usage

format_indicator(x)

Arguments

x

PEPFAR indicator name as an abbreviation and the full definition

Value

html formatted string that can be rendered in gt

See Also

Other MDB helper functions: calc_growth(), label_aggregation(), make_achv_shape(), make_chg_shape()

Examples

## 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)

Label aggregation level

Description

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

Usage

label_aggregation(df, type = "OU")

Arguments

df

MSD or genie data frame that has been ran through collapse_base_tbl()

type

Level of aggregation to be labeled

See Also

Other MDB helper functions: calc_growth(), format_indicator(), make_achv_shape(), make_chg_shape()


Object pointing to github location of legend for Q1

Description

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.

Usage

legend

Format

An object of class character of length 1.

See Also

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()


Object pointing to github location of legend for Q1

Description

Use legend instead as quarterly legends are no longer necessary

Usage

legend_q1

Format

An object of class character of length 1.

See Also

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()


Object pointing to github location of legend for Q2

Description

Use legend instead as quarterly legends are no longer necessary

Usage

legend_q2

Format

An object of class character of length 1.

See Also

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()


Object pointing to github location of legend for Q3

Description

Use legend instead as quarterly legends are no longer necessary

Usage

legend_q3

Format

An object of class character of length 1.

See Also

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()


Object pointing to github location of legend for snapshot indicators and Q4

Description

Use legend instead as quarterly legends are no longer necessary

Usage

legend_snapshot

Format

An object of class character of length 1.

See Also

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()


Generate colored circle as an svg

Description

Description Function to create and color achievement circles. The circles are placed next to the most recent achievement level in the main MDB table.

Usage

make_achv_shape(x)

Arguments

x

color hex code created by adorn_achievement function

Details

Returns a html formatting circle that can be embedded in gt object

Value

return gt html() code for an svg

See Also

Other MDB helper functions: calc_growth(), format_indicator(), label_aggregation(), make_chg_shape()

Examples

## Not run: 
 achv_circle(glitr::scooter) %>% htmltools::html_print()
 df %>% mutate(achv_color = achv_circle(achv_color)) 
## End(Not run)

Create fontawesome performance arrow

Description

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()

Usage

make_chg_shape(change_dir)

Arguments

change_dir

variable indicating direction of change or not applicable

Value

gt html() code for an svg

See Also

Other MDB helper functions: calc_growth(), format_indicator(), label_aggregation(), make_achv_shape()

Examples

## 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)

Create a base table of MDB indicators stacked long

Description

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()

Usage

make_mdb_df(df, resolve_issues = T)

Arguments

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

Value

data frame

See Also

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()

Examples

## Not run: 
 mdb_df <- make_mdb_df(ou_im, resolve_issues = F)
## End(Not run)

Creates the base table for the treatment / VLS MDB tables

Description

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.

Usage

make_mdb_tx_df(df, resolve_issues = "TRUE", tx_indic = "TX_CURR")

Arguments

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

Value

data frame of the combined TX and VLS/VLC indicator

See Also

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()


GT theme for main MDB tables

Description

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.

Usage

mdb_main_theme(df, ...)

Arguments

df

reshape_mdb_df() output

...

dot-dot-dot option to pass additional formatting to gt object

Value

formatted gt object

See Also

Other MDB gt themes: mdb_treatment_theme()

Examples

## 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)

mdb_tbl: Example Data Set

Description

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.

Usage

mdb_tbl

Format

A data frame with 16 rows and 7 variables:

indic_category

Indicator category, such as prevention, testing, or treatment.

indicator

Short code for the indicator.

indicator_plain

Plain text description of the indicator.

frequency

Frequency of data collection, either quarterly or semi-annual.

type

Type of data collected, such as cumulative, snapshot, or derived.

mdb_table

Table the indicator belongs to, either main or treatment.

Source

http://example.com

Examples

## Not run: 
# Example of accessing the dataset
data(mdb_tbl)
head(mdb_tbl)

## End(Not run)

GT theme for main MDB tables

Description

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.

Usage

mdb_treatment_theme(df, ...)

Arguments

df

a dataframe from reshape_mdb_tx_df() output

...

dot-dot-dot option to pass additional formatting to gt object

Value

formatted gt object

See Also

Other MDB gt themes: mdb_main_theme()

Examples

## 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)

Identify MSD Period and Type

Description

requires having si_path setup from glamr

Usage

msd_period(type = "OU_IM", period = NULL)

Arguments

type

Type of MSD (OU_IM, PSNU, PSNU_IM, NAT_SUBNAT)

period

can provide period from ICPIutilities::identifypd(), or it will run if NULL

Value

FY00Q0t MSD


Prepare filtered data frame for MSD briefer formatting

Description

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.

Usage

reshape_mdb_df(df)

Arguments

df

takes the make_mdb_df() results as an input

Value

returns a wide formatted data frame (table) of all OUs, countries and USAID

See Also

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()

Examples

## Not run: 
 mdb_df <- make_mdb_df(ou_im, resolve_issues = F)
 mdb_tbl <- reshape_mdb_df(mdb_df)
 
## End(Not run)

Prepare filtered data frame of treatment indicators for MDB formatting

Description

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.

Usage

reshape_mdb_tx_df(df)

Arguments

df

dataframe that is the result of running make_mdb_tx_df()

Details

Create a wide formatted and sorted table for treatment indicators

Value

data frame that is pivoted wide for passing to gt() call

See Also

Other data frame munging: collapse_base_tbl(), collapse_vlc_tbl(), make_mdb_df(), make_mdb_tx_df(), reshape_mdb_df()

Examples

## Not run: 
 mdb_df <- make_mdb_tx_df(ou_im, resolve_issues = F)
 mdb_tbl <- reshape_mdb_tx_df(mdb_df)
 
## End(Not run)

Set metadata

Description

Sets the metadata for the package, which can be used across various functions.

Usage

set_metadata(meta)

Arguments

meta

A list containing metadata information.

Examples

## Not run: 
 metadata <- gophr::get_metadata(file_path)
 set_metadata(metadata)

## End(Not run)