Skip to content

Commit

Permalink
Added adsl_vars as global object (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndersAskeland committed Oct 23, 2024
1 parent 185ccac commit e76c679
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions inst/templates/ad_advs.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ library(dplyr)
library(stringr)


# Set subject keys ----
# Define project options/variables ----
# Use the admiral option functionality to store subject key variables in one
# place

set_admiral_options(subject_keys = exprs(STUDYID, USUBJID))

# Store ADSL join variables as an R object, enabling simplified usage throughout
# the program
adsl_vars <- exprs(TRTSDT, TRTEDT, TRT01P, TRT01A)


# Read in data ----
# See the "Read in Data" vignette section for more information:
Expand All @@ -34,12 +37,12 @@ advs <- vs_metabolic %>%
adsl <- adsl %>%
convert_blanks_to_na()

# Merge ADSL variables (TRTSDT, TRTEDT, TRT01P, TRT01A) needed for ADVS
# Merge ADSL variables (stored in `adsl_vars`) needed for ADVS
# derivations
advs <- advs %>%
derive_vars_merged(
dataset_add = adsl,
new_vars = exprs(TRTSDT, TRTEDT, TRT01P, TRT01A),
new_vars = adsl_vars,
by_vars = get_admiral_option("subject_keys")
)

Expand Down Expand Up @@ -120,7 +123,7 @@ advs <- advs %>%
filter(VSTESTCD != "BMI") %>%
derive_param_bmi(
by_vars = exprs(
STUDYID, USUBJID, TRTSDT, TRTEDT, TRT01P, TRT01A, AVISIT,
STUDYID, USUBJID, !!!adsl_vars,
AVISITN, ADT, ADY, ATPT, ATPTN
),
set_values_to = exprs(
Expand Down Expand Up @@ -238,16 +241,17 @@ advs <- advs %>%
# See the "Add ADSL variables" vignette section for more information:
# (https://pharmaverse.github.io/admiral/articles/bds_finding.html#adsl_vars)

# Add all ADSL variables besides TRTSDT, TRTEDT, TRT01P, TRT01A
# Add all ADSL variables besides TRTSDT, TRTEDT, TRT01P, TRT01A (stored in
# `adsl_vars`)
advs <- advs %>%
derive_vars_merged(
dataset_add = select(adsl, !!!negate_vars(exprs(TRTSDT, TRTEDT, TRT01P, TRT01A))),
dataset_add = select(adsl, !!!negate_vars(adsl_vars)),
by_vars = get_admiral_option("subject_keys")
)


# Add Labels and Attributes ----
# This process is commonly based on your metadata. As such, no specific example
# This process is usually based on one's metadata. As such, no specific example
# will be given. See the "Add Labels and Attributes" vignette section for
# description of several open source R packages which can be used to handle
# metadata.
Expand Down

0 comments on commit e76c679

Please sign in to comment.