derive_vars_query: Derive Query Variables

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/derive_vars_query.R

Description

Derive Query Variables

Usage

1
derive_vars_query(dataset, dataset_queries)

Arguments

dataset

Input dataset.

dataset_queries

A data.frame containing required columns VAR_PREFIX, QUERY_NAME, TERM_LEVEL, TERM_NAME, TERM_ID, and optional columns QUERY_ID, QUERY_SCOPE, QUERY_SCOPE_NUM.

The content of the dataset will be verified by assert_valid_queries().

Details

For each unique element in VAR_PREFIX, the corresponding "NAM" variable will be created. For each unique VAR_PREFIX, if QUERY_ID is not "" or NA, then the corresponding "CD" variable is created; similarly, if QUERY_SCOPE is not "" or NA, then the corresponding "SC" variable will be created; if QUERY_SCOPE_NUM is not "" or NA, then the corresponding "SCN" variable will be created.

For each record in dataset, the "NAM" variable takes the value of QUERY_NAME if the value of TERM_NAME or TERM_ID in dataset_queries matches the value of the respective TERM_LEVEL in dataset. Note that TERM_NAME in dataset_queries dataset may be NA only when TERM_ID is non-NA and vice versa. The "CD", "SC", and "SCN" variables are derived accordingly based on QUERY_ID, QUERY_SCOPE, and QUERY_SCOPE_NUM respectively, whenever not missing.

Value

The input dataset with query variables derived.

Author(s)

Ondrej Slama, Shimeng Huang

See Also

assert_valid_queries()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
data("queries")
adae <- tibble::tribble(
  ~USUBJID, ~ASTDTM, ~AETERM, ~AESEQ, ~AEDECOD, ~AELLT, ~AELLTCD,
  "01", "2020-06-02 23:59:59", "ALANINE AMINOTRANSFERASE ABNORMAL",
    3, "Alanine aminotransferase abnormal", NA_character_, NA_integer_,
  "02", "2020-06-05 23:59:59", "BASEDOW'S DISEASE",
    5, "Basedow's disease", NA_character_, 1L,
  "03", "2020-06-07 23:59:59", "SOME TERM",
    2, "Some query", "Some term", NA_integer_,
  "05", "2020-06-09 23:59:59", "ALVEOLAR PROTEINOSIS",
    7, "Alveolar proteinosis", NA_character_,  NA_integer_
)
derive_vars_query(adae, queries)

epijim/admiral documentation built on Feb. 13, 2022, 12:15 a.m.