Example of Functions Part I

The goal of CME.assistant is to share reusable helper functions within the CME team. Also feel free to download, further revise and compile locally.

options(rmarkdown.html_vignette.check_title = FALSE)
library(CME.assistant)
#> Loading required package: data.table

Functions for data engineering

Read the final aggregated file and output final IGME estimates in various forms

Choose output format among raw, long, wide_year and wide_ind, default to “long”
* The long-format dataset contains Official Name, ISO3Code, Indicator, Year, Quantile, Sex * The function will output all available indicators in the dataset * Optional: subset by country ISO (c_iso) or year (year_range)

get.CME.UI.data

# without supplying dir_file, by default returns the published IGME 2020 final
# results
dt_1 <- get.CME.UI.data(use_IGME_year = 2020)
#> Indicators:U5MR, IMR, NMR, Under.five.Deaths, Infant.Deaths, Neonatal.Deaths
head(dt_1)
#>    OfficialName ISO3Code Indicator Year Quantile   Sex Value
#> 1:  Afghanistan      AFG       IMR 1990    Lower Total 111.2
#> 2:  Afghanistan      AFG       IMR 1990   Median Total 120.4
#> 3:  Afghanistan      AFG       IMR 1990    Upper Total 130.9
#> 4:  Afghanistan      AFG       IMR 1991    Lower Total 108.2
#> 5:  Afghanistan      AFG       IMR 1991   Median Total 116.8
#> 6:  Afghanistan      AFG       IMR 1991    Upper Total 126.2
# can read final output file from Dropbox for any indicator
# loading Dropbox files requires access to corresponding files
dir_list <- load.final_dir()
dt_2 <- get.CME.UI.data(dir_file = dir_list$dir_female_2020)
head(dt_2)

Make CC profiles

dir_cqt_files <- file.path(CME.assistant::get.IGME.dir(2020),
                           "figData/cqt_backup")
list.files(dir_cqt_files)
dt_cqt <- get.dt.cqt(dir_cqt_files)
dt_cqt[, table(Shortind, Sex)]
# table to be added into the profile by country: 
dt1 <- get.table.by.iso(iso0 = "AFG")

Locate the latest master datasets directories

Automatically point to the latest file using the date in file names

input_dirs <- load.IGMEinput.dir()
dir_U5MR   <- get.dir_U5MR(input_dirs$dir_IGME_20)
dir_IMR    <- get.dir_IMR(input_dirs$dir_IGME_20)
dir_NMR    <- get.dir_NMR(y5 = TRUE) # either 5-year or not
dir_gender <- get.dir_gender(plotting = TRUE) # either dataset for plotting or modeling

Extra

get.match

# a helpful function to revise variable, you can provide a __new_list__ to define the labels
get.match(c("a","b", "c"), new_list = list("a" = "new label 1",
                                           "b" = "new label 2"))
#> [1] "new label 1" "new label 2" "c"

UNICEF_colors

str(UNICEF_colors)
#> List of 5
#>  $ UNICEF_blue    : chr "#1CABE2"
#>  $ cp_UNICEF_seq  : chr [1:8] "#002759" "#00377D" "#0058AB" "#0083CF" ...
#>  $ cp_UNICEF_div  : chr [1:10] "#002759" "#0058AB" "#1CABE2" "#69DBFF" ...
#>  $ cp_UNICEF_qua  : chr [1:10] "#0058AB" "#1CABE2" "#00833D" "#80BD41" ...
#>  $ cp_UNICEF_grays: chr [1:5] "#333333" "#6B6B6B" "#B3B3B3" "#D7D7D7" ...