Skip to contents

This family of functions can be used to extract decode_tbls from vectors of variable names and decodes. Generally, users are expected to use extract_decode_tbls.

extract_decode_tbl

Generates a decode_tbl for one variable name and set of decodes.

extract_decode_tbls

Generates a decode_tbls list given vectors of variable names and decodes. Results with no identified decodes are dropped.

Usage

extract_decode_tbl(variable_name, decode)

extract_decode_tbls(variable_name, decode)

Arguments

variable_name

A character vector of variable names.

decode

A character vector. Items are expected to be separated by new lines. Name-value pairs should be separated by a single equal sign.

See also

extract_decode_tbls_from_data to extract decode_tbls from a dataset; join_decode_labels and join_decode_levels to merge decode_tbls to a dataset.

Examples

possible_decodes <- tibble::tribble(
  ~var,     ~decode,
  # compact
  "SEXF",   "0=Male\n1=Female",                                                        
  # yes/no without single quotes
  "LGL",    "Y=Yes\nN=No",                                                             
  # yes/no with single quotes
  "LGLQ",   "'Y'=Yes\n'N'=No",                                                         
  # with spaces and numbers
  "AGEPED", "0=Neonate to 1 month\n1=Infant: 1 month to 2 years",                      
  # with parentheses in decode
  "MDV",    "0=PK or PD measure\n1=Dose or Other(EVID=2)",                             
  # with special characters and parentheses
  "RFCAT",  "1=Normal (>=90 mL/min)\n2=Mild (60-89 mL/min)\n3=Moderate (30-59 mL/min)",
  # item that does not include encoding
  "BAD",    "This is not a decode"                                                     
)

extract_decode_tbls(possible_decodes$var, possible_decodes$decode)
#> 
#> ── Decode tables ───────────────────────────────────────────────────────────────
#> 
#> ── SEXF ──
#> 
#> 0=Male
#> 1=Female
#> 
#> ── LGL ──
#> 
#> N=No
#> Y=Yes
#> 
#> ── LGLQ ──
#> 
#> N=No
#> Y=Yes
#> 
#> ── AGEPED ──
#> 
#> 0=Neonate to 1 month
#> 1=Infant: 1 month to 2 years
#> 
#> ── MDV ──
#> 
#> 0=PK or PD measure
#> 1=Dose or Other(EVID=2)
#> 
#> ── RFCAT ──
#> 
#> 1=Normal (>=90 mL/min)
#> 2=Mild (60-89 mL/min)
#> 3=Moderate (30-59 mL/min)

possible_decodes |> 
  with(extract_decode_tbls(var, decode))
#> 
#> ── Decode tables ───────────────────────────────────────────────────────────────
#> 
#> ── SEXF ──
#> 
#> 0=Male
#> 1=Female
#> 
#> ── LGL ──
#> 
#> N=No
#> Y=Yes
#> 
#> ── LGLQ ──
#> 
#> N=No
#> Y=Yes
#> 
#> ── AGEPED ──
#> 
#> 0=Neonate to 1 month
#> 1=Infant: 1 month to 2 years
#> 
#> ── MDV ──
#> 
#> 0=PK or PD measure
#> 1=Dose or Other(EVID=2)
#> 
#> ── RFCAT ──
#> 
#> 1=Normal (>=90 mL/min)
#> 2=Mild (60-89 mL/min)
#> 3=Moderate (30-59 mL/min)