msf_dict: MSF data dictionaries and dummy datasets

Description Usage Arguments See Also Examples

View source: R/msf_dict.R

Description

These function produces MSF OCA dictionaries based on DHIS2 data sets defining the data element name, code, short names, types, and key/value pairs for translating the codes into human-readable format.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
msf_dict(
  disease,
  name = "MSF-outbreak-dict.xlsx",
  tibble = TRUE,
  compact = TRUE,
  long = TRUE
)

msf_dict_survey(
  disease,
  name = "MSF-survey-dict.xlsx",
  tibble = TRUE,
  compact = FALSE
)

Arguments

disease

Specify which disease you would like to use.

  • msf_dict() supports "AJS", "Cholera", "Measles", "Meningitis"

  • msf_dict_survey() supports "Mortality", "Nutrition", and "Vaccination"

name

the name of the dictionary stored in the package.

tibble

Return data dictionary as a tidyverse tibble (default is TRUE)

compact

if TRUE (default), then a nested data frame is returned where each row represents a single variable and a nested data frame column called "options", which can be expanded with tidyr::unnest(). This only works if long = TRUE.

long

If TRUE (default), the returned data dictionary is in long format with each option getting one row. If FALSE, then two data frames are returned, one with variables and the other with content options.

See Also

matchmaker::match_df() gen_data() msf_dict_survey()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
if (require("dplyr") & require("matchmaker")) {
  withAutoprint({
    # You will often want to use MSF dictionaries to translate codes to human-
    # readable variables. Here, we generate a data set of 20 cases:
    dat <- gen_data(
      dictionary = "Cholera", 
      varnames = "data_element_shortname",
      numcases = 20, 
      org = "MSF"
    )
    print(dat)

    # We want the expanded dictionary, so we will select `compact = FALSE`
    dict <- msf_dict(disease = "Cholera", long = TRUE, compact = FALSE, tibble = TRUE)
    print(dict)

    # Now we can use matchmaker to filter the data:
    dat_clean <- matchmaker::match_df(dat, dict,
      from = "option_code",
      to = "option_name",
      by = "data_element_shortname",
      order = "option_order_in_set"
    )
    print(dat_clean)
  })
}

R4EPI/epidict documentation built on Feb. 16, 2020, 10:17 p.m.