Example of Functions Part I"

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

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)

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)
head(dt_1)
# 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"))

UNICEF_colors

str(UNICEF_colors)


Try the CME.assistant package in your browser

Any scripts or data that you put into this service are public.

CME.assistant documentation built on March 22, 2021, 5:07 p.m.