diff --git a/DESCRIPTION b/DESCRIPTION index 1a8c685e..54993ee1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -58,7 +58,6 @@ Imports: lifecycle (>= 0.1.0), lubridate (>= 1.7.4), magrittr (>= 1.5), - metatools, purrr (>= 0.3.3), rlang (>= 0.4.4), stringr (>= 1.4.0), @@ -80,7 +79,8 @@ Suggests: spelling, testthat, tibble, - usethis + usethis, + metatools VignetteBuilder: knitr Encoding: UTF-8 diff --git a/NAMESPACE b/NAMESPACE index 4db4d77c..6a3fbe90 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -87,7 +87,6 @@ importFrom(lubridate,years) importFrom(lubridate,ymd) importFrom(lubridate,ymd_hms) importFrom(magrittr,"%>%") -importFrom(metatools,combine_supp) importFrom(purrr,compose) importFrom(purrr,every) importFrom(purrr,flatten) diff --git a/NEWS.md b/NEWS.md index 1bc01627..d25a87e2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,12 @@ -# admiralvaccine (development version) +# admiralvaccine 0.3.0 + +## Breaking Changes + +- Removed `dataset_supp` and `dataset_suppex` arguments from `derive_vars_merged_vaccine()` as we are not combining the parental with supplementary inside the function, but can be optionally combined in the ADCE, ADFACE and ADIS templates using `combine_supp()` function from {metatools}. (#246) + +## Updates to Templates + +- Supplementary domains are now optionally combined with parental domain within the template. (#246) # admiralvaccine 0.2.0 diff --git a/R/admiralvaccine.R b/R/admiralvaccine.R index 8fcf9918..46099173 100644 --- a/R/admiralvaccine.R +++ b/R/admiralvaccine.R @@ -32,5 +32,4 @@ #' @importFrom admiraldev assert_logical_scalar assert_character_vector assert_vars #' assert_data_frame assert_character_scalar assert_numeric_vector assert_filter_cond #' assert_symbol assert_expr_list expect_dfs_equal -#' @importFrom metatools combine_supp "_PACKAGE" diff --git a/R/derive_vars_merged_vaccine.R b/R/derive_vars_merged_vaccine.R index cf666435..2d43f239 100644 --- a/R/derive_vars_merged_vaccine.R +++ b/R/derive_vars_merged_vaccine.R @@ -4,27 +4,15 @@ #' The variables to be added to the output dataset will be based on input variables #' passed on `ex_vars` argument. #' -#' @param dataset Input dataset +#' @param dataset Input dataset which should have been combined with the supplementary(if exists). #' #' The variables specified by the `by_vars` argument inside the #' `derive_vars_merged`are expected. #' -#' @param dataset_ex EX dataset to merge with the input dataset. +#' @param dataset_ex `ex` dataset(combined with `suppex`) to merge with the input dataset. #' #' The variables specified by the `ex_vars` argument are expected. #' -#' @param dataset_supp Supplementary input dataset -#' -#' By default `dataset_supp` will be `NULL`, user has to provide -#' supplementary dataset to merge it back with original input dataset -#' if they have supplementary dataset in their case. -#' -#' @param dataset_suppex Supplementary EX dataset -#' -#' By default `dataset_suppex` will be `NULL`, user has to provide -#' supplementary dataset to merge it back with original `EX` dataset -#' if they have supplementary dataset in their case. -#' #' @param by_vars_sys Grouping variables for systemic events. #' #' @param by_vars_adms Grouping variables for administration site events. @@ -45,8 +33,7 @@ #' Only the variables passed to the `ex_vars` will be added in the output dataset #' #' If the input dataset has multiple vaccination for a subject at same visit -#' then this function will not merge ex dataset and will return only the input -#' dataset merged with its supplementary dataset. +#' then this function will not merge ex dataset and will return the `dataset`. #' #' @author Vikram S #' @@ -66,8 +53,6 @@ #' derive_vars_merged_vaccine( #' dataset = face_vaccine, #' dataset_ex = ex_vaccine, -#' dataset_supp = NULL, -#' dataset_suppex = NULL, #' by_vars_sys = exprs(USUBJID, FATPTREF = EXLNKGRP), #' by_vars_adms = exprs(USUBJID, FATPTREF = EXLNKGRP, FALOC = EXLOC, FALAT = EXLAT), #' ex_vars = exprs(EXTRT, EXDOSE, EXDOSU, EXSTDTC, EXENDTC) @@ -78,38 +63,21 @@ #' derive_vars_merged_vaccine( #' dataset = face_vaccine, #' dataset_ex = ex_vaccine, -#' dataset_supp = suppface_vaccine, -#' dataset_suppex = suppex_vaccine, #' by_vars_sys = exprs(USUBJID, FATPTREF = EXLNKGRP), #' by_vars_adms = exprs(USUBJID, FATPTREF = EXLNKGRP, FALOC = EXLOC, FALAT = EXLAT), #' ex_vars = exprs(EXTRT, EXDOSE, EXDOSU, EXSTDTC, EXENDTC) -#' ) %>% -#' filter(CLTYP == "DAIRY") %>% -#' select(USUBJID, FATPTREF, CLTYP, EXTRT, EXDOSE, EXDOSU, EXSTDTC, EXENDTC) +#' ) +#' derive_vars_merged_vaccine <- function(dataset, dataset_ex, by_vars_sys, by_vars_adms, - dataset_supp = NULL, - dataset_suppex = NULL, ex_vars) { assert_data_frame(dataset) assert_vars(by_vars_sys) assert_vars(by_vars_adms) assert_vars(ex_vars) - assert_data_frame(dataset_supp, optional = TRUE) assert_data_frame(dataset_ex) - assert_data_frame(dataset_suppex, optional = TRUE) - - # combine face and suppface dataset - if (!is.null(dataset_supp)) { - dataset <- combine_supp(dataset, dataset_supp) - } - - # combine face and suppex dataset - if (!is.null(dataset_suppex)) { - dataset_ex <- combine_supp(dataset_ex, dataset_suppex) - } if ("VISIT" %in% names(dataset_ex)) { ex_distinct <- dataset_ex %>% distinct(USUBJID, VISIT, .keep_all = TRUE) @@ -119,8 +87,7 @@ derive_vars_merged_vaccine <- function(dataset, if (nrow(dataset_ex) != nrow(ex_distinct)) { warning("Subjects have multiple vaccinations at same visit") - - dataset <- dataset + return(dataset) } else { # Filter records for ADMINISTRATION SITE events and merge it with EX dataset dataset_adminstration <- dataset %>% @@ -145,6 +112,6 @@ derive_vars_merged_vaccine <- function(dataset, ) # bind face1 and face2 datasets - bind_rows(face1, face2) + return(bind_rows(face1, face2)) } } diff --git a/inst/templates/ad_adce.R b/inst/templates/ad_adce.R index 0a2d78ae..164192b2 100644 --- a/inst/templates/ad_adce.R +++ b/inst/templates/ad_adce.R @@ -56,7 +56,7 @@ adce02 <- adce01 %>% derive_vars_merged( dataset_add = adsl, new_vars = adsl_vars, - by = exprs(STUDYID, USUBJID) + by = get_admiral_option("subject_keys") ) %>% ## Derive analysis start time ## Proposed imputations depending on situation: no needed -> highest imputation = ā€œnā€ @@ -84,7 +84,7 @@ adce03 <- derive_vars_joined( adce02, dataset_add = adperiods, - by_vars = exprs(STUDYID, USUBJID), + by_vars = get_admiral_option("subject_keys"), filter_join = ASTDT >= APERSDT & ASTDT <= APEREDT, join_type = "all" ) %>% @@ -121,7 +121,7 @@ adce05 <- adce04 %>% ## Derive ASEQ derive_var_obs_number( new_var = ASEQ, - by_vars = exprs(STUDYID, USUBJID), + by_vars = get_admiral_option("subject_keys"), order = exprs(CEDECOD, CELAT, CETPTREF, APERIOD), check_type = "error" ) %>% @@ -146,7 +146,7 @@ adsl_list <- adsl %>% adce <- adce05 %>% derive_vars_merged( dataset_add = adsl_list, - by_vars = exprs(STUDYID, USUBJID) + by_vars = get_admiral_option("subject_keys") ) diff --git a/inst/templates/ad_adface.R b/inst/templates/ad_adface.R index 63e23699..844cbef0 100644 --- a/inst/templates/ad_adface.R +++ b/inst/templates/ad_adface.R @@ -58,13 +58,17 @@ face <- face %>% adsl_vars <- exprs(RFSTDTC, RFENDTC) +# Combine the parental datasets with their respective supp datasets (only if exist) +# User can use `combine_supp()` from {metatools} to combine the parental with supp dataset. + +face <- metatools::combine_supp(face, suppface) +ex <- metatools::combine_supp(ex, suppex) + # Step 2 - Merging supplementary datasets and FACE with EX adface <- derive_vars_merged_vaccine( dataset = face, dataset_ex = ex, - dataset_supp = suppface, - dataset_suppex = suppex, by_vars_sys = exprs(USUBJID, FATPTREF = EXLNKGRP), by_vars_adms = exprs(USUBJID, FATPTREF = EXLNKGRP, FALOC = EXLOC, FALAT = EXLAT), ex_vars = exprs(EXTRT, EXDOSE, EXSEQ, EXSTDTC, EXENDTC, VISIT, VISITNUM) @@ -73,7 +77,7 @@ adface <- derive_vars_merged_vaccine( derive_vars_merged( dataset_add = adsl, new_vars = adsl_vars, - by_vars = exprs(STUDYID, USUBJID) + by_vars = get_admiral_option("subject_keys") ) %>% # Step 4 - Deriving Fever OCCUR records from VS if FAOBJ = "FEVER" records not present in FACE derive_fever_records( @@ -103,7 +107,7 @@ period_ref <- create_period_dataset( adface <- derive_vars_joined( adface, dataset_add = period_ref, - by_vars = exprs(STUDYID, USUBJID), + by_vars = get_admiral_option("subject_keys"), filter_join = ADT >= APERSDT & ADT <= APEREDT, join_type = "all" ) %>% @@ -208,7 +212,7 @@ lookup_dataset <- tribble( "MAXDIAM", "MDISW", 29, "Maximum Diameter", "SWELLING", "MAXSEV", "MAXSPIS", 30, "Maximum Severity", "PAIN AT INJECTION SITE", "OCCUR", "OCCVOM", 31, "Occurrence Indicator", "VOMITING", - "DIAMETER", "DIASWEL", 32, "Diameter", "SWELLING", + "DIAMETER", "DIASWEL", 32, "Diameter", "SWELLING" ) adface <- derive_vars_params( @@ -237,7 +241,7 @@ adsl <- adsl %>% adface <- derive_vars_merged( dataset = adface, dataset_add = select(adsl, !!!negate_vars(adsl_vars)), - by_vars = exprs(STUDYID, USUBJID) + by_vars = get_admiral_option("subject_keys") ) %>% # Step 16 post processing post_process_reacto( @@ -261,13 +265,11 @@ keep_vars <- c( "APEREDT", "APERETM", "APEREDTM", "APERDY", "FAORRES" ) -adface <- adface %>% select( +admiralvaccine_adface <- adface %>% select( any_of(keep_vars), starts_with("TRT0"), starts_with("VAX"), starts_with("EVE"), starts_with("ANL") ) -admiralvaccine_adface <- adface - # Save output ---- dir <- tools::R_user_dir("admiralvaccine_templates_data", which = "cache") diff --git a/inst/templates/ad_adis.R b/inst/templates/ad_adis.R index 8d5b32d3..a97dd680 100644 --- a/inst/templates/ad_adis.R +++ b/inst/templates/ad_adis.R @@ -5,10 +5,8 @@ # Input: is, suppis, adsl library(admiral) library(dplyr) -library(lubridate) library(admiralvaccine) library(pharmaversesdtm) -library(metatools) # Load source datasets ---- @@ -16,6 +14,7 @@ data("is_vaccine") data("suppis_vaccine") data("admiralvaccine_adsl") + # When SAS datasets are imported into R using haven::read_sas(), missing # character values from SAS appear as "" characters in R, instead of appearing # as NA values. Further details can be obtained via the following link: @@ -31,11 +30,11 @@ adsl <- convert_blanks_to_na(admiralvaccine_adsl) # STEP 1 - combine IS with SUPPIS. # Please, upload MOCK data -is_suppis <- combine_supp(is, suppis) +is_suppis <- metatools::combine_supp(is, suppis) # STEP 2 - Visits and timing variables derivation. -adis_avisit <- is_suppis %>% +adis <- is_suppis %>% mutate( AVISITN = as.numeric(VISITNUM), AVISIT = case_when( @@ -44,11 +43,7 @@ adis_avisit <- is_suppis %>% VISITNUM == 30 ~ "Visit 3", VISITNUM == 40 ~ "Visit 4", is.na(VISITNUM) ~ NA_character_ - ) - ) - -adis_atpt <- adis_avisit %>% - mutate( + ), ATPTN = as.numeric(VISITNUM / 10), ATPT = case_when( VISITNUM == 10 ~ "Visit 1 (Day 1)", @@ -70,31 +65,29 @@ adis_atpt <- adis_avisit %>% # ADT derivation and Merge with ADSL to get RFSTDTC info in order to derive ADY # Add also PPROTFL from ADSL (to avoid additional merges) in order to derive # PPSRFL at step 11. -adis_adt <- derive_vars_dt( - dataset = adis_atpt, +adis <- derive_vars_dt( + dataset = adis, new_vars_prefix = "A", dtc = ISDTC, highest_imputation = "M", date_imputation = "mid", flag_imputation = "none" -) - -# ADY derivation -# Attach RFSTDTC from ADSL in order to derive ADY -adis_ady <- adis_adt %>% +) %>% derive_vars_merged( dataset_add = adsl, new_vars = exprs(RFSTDTC, PPROTFL), - by_vars = exprs(STUDYID, USUBJID) + by_vars = get_admiral_option("subject_keys") ) %>% mutate( - RFSTDT = as.Date(RFSTDTC) + ADT = as.Date(ADT), + RFSTDTC = as.Date(RFSTDTC) ) %>% + # ADY derivation derive_vars_dy( - reference_date = RFSTDT, + reference_date = RFSTDTC, source_vars = exprs(ADT) - ) %>% - select(-RFSTDT) + ) + # STEP 4: PARAMCD, PARAM and PARAMN derivation @@ -104,39 +97,39 @@ adis_ady <- adis_adt %>% # Please, keep or modify PARAM values according to your purposes. # Put ISSEQ empty for derived records. -# If you would like to maintain traceability, please delete these part of the code. +# If you would like to maintain traciability, please delete these part of the code. -is_log <- adis_ady %>% +is_log <- adis %>% mutate( DERIVED = "LOG10", ISSEQ = NA_real_ ) -is_4fold <- adis_ady %>% +is_4fold <- adis %>% mutate( DERIVED = "4FOLD", ISSEQ = NA_real_ ) -is_log_4fold <- adis_ady %>% +is_log_4fold <- adis %>% mutate( DERIVED = "LOG10 4FOLD", ISSEQ = NA_real_ ) -adis_der <- bind_rows(adis_ady, is_log, is_4fold, is_log_4fold) %>% +adis <- bind_rows(adis, is_log, is_4fold, is_log_4fold) %>% arrange(STUDYID, USUBJID, !is.na(DERIVED), ISSEQ) %>% mutate(DERIVED = if_else(is.na(DERIVED), "ORIG", DERIVED)) -adis_paramcd <- adis_der %>% +adis <- adis %>% mutate( # PARAMCD: for log values, concatenation of L and ISTESTCD. PARAMCD = case_when( DERIVED == "ORIG" ~ ISTESTCD, DERIVED == "LOG10" ~ paste0(ISTESTCD, "L"), DERIVED == "4FOLD" ~ paste0(ISTESTCD, "F"), - # As per CDISC rule, PARAMCD should be 8 charcaters long. Please, adapt if needed + # As per CDISC rule, PARAMCD should be 8 characters long. Please, adapt if needed DERIVED == "LOG10 4FOLD" ~ paste0(substr(ISTESTCD, 1, 6), "LF") ) ) @@ -163,16 +156,15 @@ param_lookup <- tribble( "R0003MLF", "LOG10 4FOLD (R0003MA Antibody)", 34 ) -adis_param_paramn <- derive_vars_merged_lookup( - dataset = adis_paramcd, +adis <- derive_vars_merged_lookup( + dataset = adis, dataset_add = param_lookup, new_vars = exprs(PARAM, PARAMN), by_vars = exprs(PARAMCD) ) - # STEP 5: PARCAT1 and CUTOFF0x derivations. -adis_parcat1_cutoff <- adis_param_paramn %>% +adis <- adis %>% mutate( PARCAT1 = ISCAT, # Please, define your additional cutoff values. Delete if not needed. @@ -183,7 +175,7 @@ adis_parcat1_cutoff <- adis_param_paramn %>% # STEP 6: AVAL, AVALU, DTYPE and SERCAT1/N derivation # AVAL derivation -adis_or <- adis_parcat1_cutoff %>% +adis_or <- adis %>% filter(DERIVED == "ORIG") %>% derive_var_aval_adis( lower_rule = ISLLOQ / 2, @@ -192,7 +184,7 @@ adis_or <- adis_parcat1_cutoff %>% round = 2 ) -adis_log_or <- adis_parcat1_cutoff %>% +adis_log_or <- adis %>% filter(DERIVED == "LOG10") %>% derive_var_aval_adis( lower_rule = log10(ISLLOQ / 2), @@ -201,7 +193,7 @@ adis_log_or <- adis_parcat1_cutoff %>% round = 2 ) -adis_4fold <- adis_parcat1_cutoff %>% +adis_4fold <- adis %>% filter(DERIVED == "4FOLD") %>% derive_var_aval_adis( lower_rule = ISLLOQ, @@ -210,7 +202,7 @@ adis_4fold <- adis_parcat1_cutoff %>% round = 2 ) -adis_log_4fold <- adis_parcat1_cutoff %>% +adis_log_4fold <- adis %>% filter(DERIVED == "LOG10 4FOLD") %>% derive_var_aval_adis( lower_rule = log10(ISLLOQ), @@ -219,7 +211,7 @@ adis_log_4fold <- adis_parcat1_cutoff %>% round = 2 ) -adis_aval_sercat1 <- bind_rows(adis_or, adis_log_or, adis_4fold, adis_log_4fold) %>% +adis <- bind_rows(adis_or, adis_log_or, adis_4fold, adis_log_4fold) %>% mutate( # AVALU derivation (please delete if not needed for your study) AVALU = ISSTRESU, @@ -242,8 +234,8 @@ param_lookup2 <- tribble( NA_character_, NA_real_ ) -adis_sercat1n <- derive_vars_merged_lookup( - dataset = adis_aval_sercat1, +adis <- derive_vars_merged_lookup( + dataset = adis, dataset_add = param_lookup2, new_vars = exprs(SERCAT1N), by_vars = exprs(SERCAT1) @@ -253,8 +245,8 @@ adis_sercat1n <- derive_vars_merged_lookup( # DTYPE derivation. # Please update code when <,<=,>,>= are present in your lab results (in ISSTRESC) -if (any(names(adis_sercat1n) == "ISULOQ") == TRUE) { - adis_dtype <- adis_sercat1n %>% +if (any(names(adis) == "ISULOQ") == TRUE) { + adis <- adis %>% mutate(DTYPE = case_when( DERIVED %in% c("ORIG", "LOG10") & !is.na(ISLLOQ) & ((ISSTRESN < ISLLOQ) | grepl("<", ISORRES)) ~ "HALFLLOQ", @@ -264,8 +256,8 @@ if (any(names(adis_sercat1n) == "ISULOQ") == TRUE) { )) } -if (any(names(adis_sercat1n) == "ISULOQ") == FALSE) { - adis_dtype <- adis_sercat1n %>% +if (any(names(adis) == "ISULOQ") == FALSE) { + adis <- adis %>% mutate(DTYPE = case_when( DERIVED %in% c("ORIG", "LOG10") & !is.na(ISLLOQ) & ((ISSTRESN < ISLLOQ) | grepl("<", ISORRES)) ~ "HALFLLOQ", @@ -274,26 +266,10 @@ if (any(names(adis_sercat1n) == "ISULOQ") == FALSE) { } -# STEP 7: BASE variables and ABLFL derivation -# BASETYPE derivation -adis_basetype <- derive_basetype_records( - adis_dtype, - basetypes = exprs("VISIT 1" = AVISITN %in% c(10, 30)) -) - -# BASE derivation -adis_base <- derive_var_base( - adis_basetype, - by_vars = exprs(STUDYID, USUBJID, PARAMN), - source_var = AVAL, - new_var = BASE, - filter = VISITNUM == 10 -) - - +# STEP 7: ABLFL and BASE variables derivation # ABLFL derivation -adis_ablfl <- restrict_derivation( - adis_base, +adis <- restrict_derivation( + adis, derivation = derive_var_extreme_flag, args = params( by_vars = exprs(STUDYID, USUBJID, PARAMN), @@ -301,13 +277,24 @@ adis_ablfl <- restrict_derivation( new_var = ABLFL, mode = "first" ), - filter = VISITNUM == 10 & !is.na(BASE) + filter = VISITNUM == 10 ) %>% - arrange(STUDYID, USUBJID, !is.na(DERIVED), VISITNUM, PARAMN) + # BASE derivation + derive_var_base( + by_vars = exprs(STUDYID, USUBJID, PARAMN), + source_var = AVAL, + new_var = BASE, + filter = ABLFL == "Y" + ) %>% + # BASETYPE derivation + derive_basetype_records( + basetypes = exprs("VISIT 1" = AVISITN %in% c(10, 30)) + ) %>% + arrange(STUDYID, USUBJID, !is.na(DERIVED), ISSEQ) # BASECAT derivation -adis_basecat <- adis_ablfl %>% +adis <- adis %>% mutate( BASECAT1 = case_when( !grepl("L", PARAMCD) & BASE < 10 ~ "Titer value < 1:10", @@ -319,28 +306,24 @@ adis_basecat <- adis_ablfl %>% # STEP 8 Derivation of Change from baseline and Ratio to baseline ---- -adis_chg <- restrict_derivation( - adis_basecat, +adis <- restrict_derivation(adis, derivation = derive_var_chg, filter = AVISITN > 10 -) - -adis_r2b <- restrict_derivation( - adis_chg, - derivation = derive_var_analysis_ratio, - args = params( - numer_var = AVAL, - denom_var = BASE - ), - filter = AVISITN > 10 ) %>% - arrange(STUDYID, USUBJID, DERIVED, ISSEQ) %>% - select(-DERIVED) + restrict_derivation( + derivation = derive_var_analysis_ratio, + args = params( + numer_var = AVAL, + denom_var = BASE + ), + filter = AVISITN > 10 + ) %>% + arrange(STUDYID, USUBJID, DERIVED, ISSEQ) # STEP 9 Derivation of CRITyFL and CRITyFN ---- -adis_crit <- derive_vars_crit( - dataset = adis_r2b, +adis <- derive_vars_crit( + dataset = adis, prefix = "CRIT1", crit_label = "Titer >= ISLLOQ", condition = !is.na(AVAL) & !is.na(ISLLOQ), @@ -354,39 +337,32 @@ period_ref <- create_period_dataset( new_vars = exprs(APERSDT = APxxSDT, APEREDT = APxxEDT, TRTA = TRTxxA, TRTP = TRTxxP) ) -adis_trt <- derive_vars_joined( - adis_crit, +adis <- derive_vars_joined( + adis, dataset_add = period_ref, - by_vars = exprs(STUDYID, USUBJID), + by_vars = get_admiral_option("subject_keys"), filter_join = ADT >= APERSDT & ADT <= APEREDT, join_type = "all" ) + # STEP 11 Derivation of PPSRFL ---- -adis_ppsrfl <- adis_trt %>% +adis <- adis %>% mutate(PPSRFL = if_else(VISITNUM %in% c(10, 30) & PPROTFL == "Y", "Y", NA_character_)) # STEP 12 Merge with ADSL ---- # Get list of ADSL variables not to be added to ADIS -adsl_vars <- exprs(RFSTDTC, PPROTFL) +vx_adsl_vars <- exprs(RFSTDTC, PPROTFL) adis <- derive_vars_merged( - dataset = adis_ppsrfl, - dataset_add = select(admiralvaccine_adsl, !!!negate_vars(adsl_vars)), - by_vars = exprs(STUDYID, USUBJID) + dataset = adis, + dataset_add = select(adsl, !!!negate_vars(vx_adsl_vars)), + by_vars = get_admiral_option("subject_keys") ) -admiralvaccine_adis <- adis - # Save output ---- - -dir <- tools::R_user_dir("admiralvaccine_templates_data", which = "cache") -# Change to whichever directory you want to save the dataset in -if (!file.exists(dir)) { - # Create the folder - dir.create(dir, recursive = TRUE, showWarnings = FALSE) -} -save(admiralvaccine_adis, file = file.path(dir, "adis.rda"), compress = "bzip2") +dir <- tempdir() # Change to whichever directory you want to save the dataset in +saveRDS(adis, file = file.path(dir, "adis.rda"), compress = "bzip2") diff --git a/inst/templates/ad_adsl.R b/inst/templates/ad_adsl.R index e067e7d1..dd566720 100644 --- a/inst/templates/ad_adsl.R +++ b/inst/templates/ad_adsl.R @@ -87,13 +87,13 @@ adsl <- dm %>% dataset_add = ex, filter_add = EXLNKGRP == "VACCINATION 1", new_vars = exprs(TRT01A = EXTRT), - by_vars = exprs(STUDYID, USUBJID) + by_vars = get_admiral_option("subject_keys") ) %>% derive_vars_merged( dataset_add = ex, filter_add = EXLNKGRP == "VACCINATION 2", new_vars = exprs(TRT02A = EXTRT), - by_vars = exprs(STUDYID, USUBJID) + by_vars = get_admiral_option("subject_keys") ) %>% ## derive treatment start date (TRTSDTM) ---- derive_vars_merged( @@ -105,7 +105,7 @@ adsl <- dm %>% new_vars = exprs(TRTSDTM = EXSTDTM), order = exprs(EXSTDTM, EXSEQ), mode = "first", - by_vars = exprs(STUDYID, USUBJID) + by_vars = get_admiral_option("subject_keys") ) %>% ## derive treatment end date (TRTEDTM) ---- derive_vars_merged( @@ -116,7 +116,7 @@ adsl <- dm %>% new_vars = exprs(TRTEDTM = EXENDTM), order = exprs(EXENDTM, EXSEQ), mode = "last", - by_vars = exprs(STUDYID, USUBJID) + by_vars = get_admiral_option("subject_keys") ) %>% ## Derive treatment end/start date TRTSDT/TRTEDT ---- derive_vars_dtm_to_dt(source_vars = exprs(TRTSDTM, TRTEDTM)) @@ -124,7 +124,7 @@ adsl <- dm %>% adsl <- derive_var_merged_exist_flag( dataset = adsl, dataset_add = ex, - by_vars = exprs(STUDYID, USUBJID), + by_vars = get_admiral_option("subject_keys"), new_var = SAFFL, condition = (EXDOSE > 0 | (EXDOSE == 0 & str_detect(EXTRT, "VACCINE"))) ) %>% diff --git a/man/derive_vars_merged_vaccine.Rd b/man/derive_vars_merged_vaccine.Rd index 16135696..b1c9eb97 100644 --- a/man/derive_vars_merged_vaccine.Rd +++ b/man/derive_vars_merged_vaccine.Rd @@ -9,18 +9,16 @@ derive_vars_merged_vaccine( dataset_ex, by_vars_sys, by_vars_adms, - dataset_supp = NULL, - dataset_suppex = NULL, ex_vars ) } \arguments{ -\item{dataset}{Input dataset +\item{dataset}{Input dataset which should have been combined with the supplementary(if exists). The variables specified by the \code{by_vars} argument inside the \code{derive_vars_merged}are expected.} -\item{dataset_ex}{EX dataset to merge with the input dataset. +\item{dataset_ex}{\code{ex} dataset(combined with \code{suppex}) to merge with the input dataset. The variables specified by the \code{ex_vars} argument are expected.} @@ -28,18 +26,6 @@ The variables specified by the \code{ex_vars} argument are expected.} \item{by_vars_adms}{Grouping variables for administration site events.} -\item{dataset_supp}{Supplementary input dataset - -By default \code{dataset_supp} will be \code{NULL}, user has to provide -supplementary dataset to merge it back with original input dataset -if they have supplementary dataset in their case.} - -\item{dataset_suppex}{Supplementary EX dataset - -By default \code{dataset_suppex} will be \code{NULL}, user has to provide -supplementary dataset to merge it back with original \code{EX} dataset -if they have supplementary dataset in their case.} - \item{ex_vars}{Variables to be added to the output dataset from EX dataset} } \value{ @@ -61,8 +47,7 @@ is expected to handle if any pre-processing is required. Only the variables passed to the \code{ex_vars} will be added in the output dataset If the input dataset has multiple vaccination for a subject at same visit -then this function will not merge ex dataset and will return only the input -dataset merged with its supplementary dataset. +then this function will not merge ex dataset and will return the \code{dataset}. } \examples{ @@ -74,8 +59,6 @@ library(pharmaversesdtm) derive_vars_merged_vaccine( dataset = face_vaccine, dataset_ex = ex_vaccine, - dataset_supp = NULL, - dataset_suppex = NULL, by_vars_sys = exprs(USUBJID, FATPTREF = EXLNKGRP), by_vars_adms = exprs(USUBJID, FATPTREF = EXLNKGRP, FALOC = EXLOC, FALAT = EXLAT), ex_vars = exprs(EXTRT, EXDOSE, EXDOSU, EXSTDTC, EXENDTC) @@ -86,14 +69,11 @@ derive_vars_merged_vaccine( derive_vars_merged_vaccine( dataset = face_vaccine, dataset_ex = ex_vaccine, - dataset_supp = suppface_vaccine, - dataset_suppex = suppex_vaccine, by_vars_sys = exprs(USUBJID, FATPTREF = EXLNKGRP), by_vars_adms = exprs(USUBJID, FATPTREF = EXLNKGRP, FALOC = EXLOC, FALAT = EXLAT), ex_vars = exprs(EXTRT, EXDOSE, EXDOSU, EXSTDTC, EXENDTC) -) \%>\% - filter(CLTYP == "DAIRY") \%>\% - select(USUBJID, FATPTREF, CLTYP, EXTRT, EXDOSE, EXDOSU, EXSTDTC, EXENDTC) +) + } \seealso{ Other der_var: diff --git a/staged_dependencies.yaml b/staged_dependencies.yaml index f1ed07fa..f47d2174 100644 --- a/staged_dependencies.yaml +++ b/staged_dependencies.yaml @@ -5,7 +5,7 @@ current_repo: upstream_repos: - repo: pharmaverse/admiral host: https://github.com - - repo: pharmaverse/admiral.test + - repo: pharmaverse/pharmaversesdtm host: https://github.com - repo: pharmaverse/admiraldev host: https://github.com diff --git a/tests/testthat/test-derive_vars_merged_vaccine.R b/tests/testthat/test-derive_vars_merged_vaccine.R index d591d974..dde20dda 100644 --- a/tests/testthat/test-derive_vars_merged_vaccine.R +++ b/tests/testthat/test-derive_vars_merged_vaccine.R @@ -1,5 +1,3 @@ -## Test 1: Merging EXTRT variable from EX to FACE - test_that("derive_vars_merged_vaccine Test 1: Merging EXTRT variable from EX to FACE", { face <- tibble::tribble( ~USUBJID, ~FACAT, ~FASCAT, ~FATESTCD, ~FAOBJ, ~FATEST, ~FALOC, ~FALAT, ~FATPTREF, @@ -43,8 +41,6 @@ test_that("derive_vars_merged_vaccine Test 1: Merging EXTRT variable from EX to actual <- derive_vars_merged_vaccine( dataset = face, dataset_ex = ex, - dataset_supp = NULL, - dataset_suppex = NULL, by_vars_sys = exprs(USUBJID, FATPTREF = EXTPTREF), by_vars_adms = exprs(USUBJID, FATPTREF = EXTPTREF, FALOC = EXLOC, FALAT = EXLAT), ex_vars = exprs(EXTRT, EXDOSE) @@ -55,123 +51,8 @@ test_that("derive_vars_merged_vaccine Test 1: Merging EXTRT variable from EX to )) }) -## Test 2: Check if supp datasets merged properly if they exist - -test_that("derive_vars_merged_vaccine Test 2: Check if supp datasets merged - properly if they exist", { - face <- tibble::tribble( - ~STUDYID, ~DOMAIN, ~USUBJID, ~FACAT, ~FASCAT, ~FATESTCD, ~FAOBJ, ~FATEST, ~FALOC, ~FALAT, - ~FATPTREF, ~FASEQ, - "ABC", "FACE", "ABC101", "REACTO", "ADMINISTRATION SITE", "SEV", "Redness", "Severity", "ARM", - "RIGHT", "VAC 1", 1, - "ABC", "FACE", "ABC101", "REACTO", "ADMINISTRATION SITE", "DIAMETER", "Redness", "Diameter", - "ARM", "LEFT", "VAC 1", 2, - "ABC", "FACE", "ABC101", "REACTO", "ADMINISTRATION SITE", "DIAM", "Redness", "Diameter", - NA, NA, "VAC 2", 3, - "ABC", "FACE", "ABC101", "REACTO", "SYSTEMIC", "OCCUR", "Fatigue", "Occurrence", - "LEG", "LEFT", "VAC 3", 5, - "ABC", "FACE", "ABC101", "REACTO", "ADMINISTRATION SITE", "OCCUR", "Erythema", - "Occurrence", "LEG", "LEFT", "VAC 3", 6, - "ABC", "FACE", "ABC101", "REACTO", "ADMINISTRATION SITE", "SEV", "Swelling", - "Severity", NA, NA, "VAC 4", 7, - "ABC", "FACE", "ABC101", "REACTO", "ADMINISTRATION SITE", "OCCUR", "Swelling", - "Occurrence", NA, NA, "VAC 4", 8, - "ABC", "FACE", "ABC102", "REACTO", "ADMINISTRATION SITE", "OCCUR", "Swelling", - "Occurrence", NA, NA, "VAC 1", 1 - ) - - ex <- tibble::tribble( - ~STUDYID, ~DOMAIN, ~USUBJID, ~EXSTDTC, ~VISITNUM, ~EXTRT, ~EXTPTREF, ~VISIT, ~EXLOC, ~EXLAT, - ~EXDOSE, ~EXSEQ, - "ABC", "EX", "ABC101", "2015-01-10", 1, "DRUG A", "VAC 1", "VISIT 1", "ARM", "RIGHT", 20, 1, - "ABC", "EX", "ABC101", "2015-01-11", 2, "DRUG A", "VAC 2", "VISIT 2", NA, NA, 30, 2, - "ABC", "EX", "ABC101", "2015-01-12", 3, "DRUG B", "VAC 3", "VISIT 3", "LEG", "LEFT", 25, 3, - "ABC", "EX", "ABC101", "2015-01-13", 4, "DRUG C", "VAC 4", "VISIT 4", NA, NA, 30, 4, - "ABC", "EX", "ABC102", "2015-01-13", 1, "DRUG B", "VAC 1", "VISIT 5", NA, NA, 10, 1 - ) - - suppface <- tibble::tribble( - ~STUDYID, ~USUBJID, ~RDOMAIN, ~IDVAR, ~IDVARVAL, ~QNAM, ~QVAL, ~QLABEL, ~QORIG, - "ABC", "ABC101", "FACE", "FASEQ", 1, "CLTYP", "DAIRY", "Collection Type", - "Predecessor", - "ABC", "ABC101", "FACE", "FASEQ", 2, "CLTYP", "CRF", "Collection Type", - "Predecessor" - ) - - suppex <- tibble::tribble( - ~STUDYID, ~USUBJID, ~RDOMAIN, ~IDVAR, ~IDVARVAL, ~QNAM, ~QVAL, ~QLABEL, ~QORIG, - "ABC", "ABC101", "EX", "EXSEQ", 1, "EXTDV", "N", "Temporary Delay of Vaccination", - "ASSIGNED", - "ABC", "ABC101", "EX", "EXSEQ", 2, "EXTDV", "Y", "Temporary Delay of Vaccination", - "ASSIGNED" - ) - - temp <- suppface %>% - pivot_wider( - id_cols = c(USUBJID, IDVAR, IDVARVAL), - names_from = QNAM, - values_from = QVAL - ) %>% - mutate(FASEQ = IDVARVAL) %>% - select(-c(IDVAR, IDVARVAL)) - facef <- left_join(face, temp, by = c("USUBJID", "FASEQ"), keep = FALSE) - face1 <- facef %>% - mutate(LOC = FALOC, LAT = FALAT, TPTREF = FATPTREF) - - tempex <- suppex %>% - pivot_wider( - id_cols = c(USUBJID, IDVAR, IDVARVAL), - names_from = QNAM, - values_from = QVAL - ) %>% - mutate(EXSEQ = IDVARVAL) %>% - select(-c(IDVAR, IDVARVAL)) - exf <- left_join(ex, tempex, by = c("USUBJID", "EXSEQ"), keep = FALSE) - - ex1 <- exf %>% - mutate(LOC = EXLOC, LAT = EXLAT, TPTREF = EXTPTREF) %>% - select(-c( - "VISITNUM", "VISIT", "EXLOC", "EXLAT", "EXSTDTC", - "EXTPTREF", "STUDYID", "DOMAIN", "EXSEQ" - )) - - admin <- face1 %>% - filter(FASCAT == "ADMINISTRATION SITE") - expected1 <- left_join(admin, - ex1, - by = c("USUBJID", "LOC", "LAT", "TPTREF"), keep = FALSE - ) %>% - select(-c("LOC", "LAT", "TPTREF")) - - sys <- face1 %>% filter(FASCAT == "SYSTEMIC") - expected2 <- left_join(sys, - ex1, - by = c("USUBJID", "TPTREF"), keep = FALSE - ) %>% - select(-c("TPTREF", "LOC.x", "LOC.y", "LAT.x", "LAT.y")) - - expected <- bind_rows(expected1, expected2) - - - actual <- derive_vars_merged_vaccine( - dataset = face, - dataset_ex = ex, - dataset_supp = suppface, - dataset_suppex = suppex, - by_vars_sys = exprs(USUBJID, FATPTREF = EXTPTREF), - by_vars_adms = exprs(USUBJID, FATPTREF = EXTPTREF, FALOC = EXLOC, FALAT = EXLAT), - ex_vars = exprs(EXTRT, EXDOSE, EXTDV) - ) - expect_dfs_equal(actual, expected, keys = c( - "USUBJID", "FAOBJ", "FATESTCD", "FATPTREF", - "FALOC", "FALAT" - )) -}) - - -## Test 3: Check if warning is raised when there are multiple vaccination in same visit -test_that("derive_vars_merged_vaccine Test 3: Check if warning is raised when +test_that("derive_vars_merged_vaccine Test 2: Check if warning is raised when there are multiple vaccination in same ", { face <- tibble::tribble( ~STUDYID, ~DOMAIN, ~USUBJID, ~FACAT, ~FASCAT, ~FATESTCD, ~FAOBJ, ~FATEST, ~FALOC, ~FALAT, @@ -207,8 +88,6 @@ test_that("derive_vars_merged_vaccine Test 3: Check if warning is raised when derive_vars_merged_vaccine( dataset = face, dataset_ex = ex, - dataset_supp = NULL, - dataset_suppex = NULL, by_vars_sys = exprs(USUBJID, FATPTREF = EXTPTREF), by_vars_adms = exprs(USUBJID, FATPTREF = EXTPTREF, FALOC = EXLOC, FALAT = EXLAT), ex_vars = exprs(EXTRT, EXDOSE) diff --git a/vignettes/adce.Rmd b/vignettes/adce.Rmd index 7adb73a8..ee474ef5 100644 --- a/vignettes/adce.Rmd +++ b/vignettes/adce.Rmd @@ -104,7 +104,7 @@ adce <- adce %>% derive_vars_merged( dataset_add = adsl, new_vars = adsl_vars, - by = exprs(STUDYID, USUBJID) + by = get_admiral_option("subject_keys") ) %>% derive_vars_dt( dtc = CESTDTC, @@ -136,7 +136,7 @@ adce <- derive_vars_joined( adce, dataset_add = adperiods, - by_vars = exprs(STUDYID, USUBJID), + by_vars = get_admiral_option("subject_keys"), filter_join = ASTDT >= APERSDT & ASTDT <= APEREDT, join_type = "all" ) %>% @@ -193,7 +193,7 @@ dataset_vignette( adce <- adce %>% derive_var_obs_number( new_var = ASEQ, - by_vars = exprs(STUDYID, USUBJID), + by_vars = get_admiral_option("subject_keys"), order = exprs(CEDECOD, CELAT, CETPTREF, APERIOD), check_type = "error" ) %>% @@ -228,7 +228,7 @@ adsl_list <- adsl %>% adce <- adce %>% derive_vars_merged( dataset_add = adsl_list, - by_vars = exprs(STUDYID, USUBJID) + by_vars = get_admiral_option("subject_keys") ) ``` diff --git a/vignettes/adface.Rmd b/vignettes/adface.Rmd index fbdd4642..b6ac9345 100644 --- a/vignettes/adface.Rmd +++ b/vignettes/adface.Rmd @@ -84,12 +84,15 @@ adsl <- convert_blanks_to_na(admiralvaccine_adsl) ## Pre-processing of Input Dataset {#input} This step involves company-specific pre-processing of required input dataset for -further analysis. In this step, we will filter records that has only reactogenicity events. +further analysis. In this step, we will filter records that has only reactogenicity events and +combine the `face` and `ex` with their supplementary datasets `suppface` and `suppex` respectively. ```{r eval=TRUE} face <- face %>% filter(FACAT == "REACTOGENICITY" & grepl("ADMIN|SYS", FASCAT)) %>% - mutate(FAOBJ = str_to_upper(FAOBJ)) + mutate(FAOBJ = str_to_upper(FAOBJ)) %>% + metatools::combine_supp(suppface) +ex <- metatools::combine_supp(ex, suppex) ``` ```{r, echo=FALSE} @@ -109,8 +112,6 @@ The function `derive_vars_merged_vaccine()` is used to merge `face` with `ex` do adface <- derive_vars_merged_vaccine( dataset = face, dataset_ex = ex, - dataset_supp = suppface, - dataset_suppex = suppex, by_vars_sys = exprs(USUBJID, FATPTREF = EXLNKGRP), by_vars_adms = exprs(USUBJID, FATPTREF = EXLNKGRP, FALOC = EXLOC, FALAT = EXLAT), ex_vars = exprs(EXTRT, EXDOSE, EXSEQ, EXSTDTC, EXENDTC, VISIT, VISITNUM) @@ -141,7 +142,7 @@ adface <- derive_vars_merged( face, dataset_add = adsl, new_vars = adsl_vars, - by_vars = exprs(STUDYID, USUBJID) + by_vars = get_admiral_option("subject_keys") ) ``` @@ -242,7 +243,7 @@ period_ref <- create_period_dataset( adface <- derive_vars_joined( adface, dataset_add = period_ref, - by_vars = exprs(STUDYID, USUBJID), + by_vars = get_admiral_option("subject_keys"), filter_join = ADT >= APERSDT & ADT <= APEREDT, join_type = "all" ) @@ -444,7 +445,7 @@ lookup_dataset <- tribble( "MAXDIAM", "MDISW", 29, "Maximum Diameter", "SWELLING", "MAXSEV", "MAXSPIS", 30, "Maximum Severity", "PAIN AT INJECTION SITE", "OCCUR", "OCCVOM", 31, "Occurrence Indicator", "VOMITING", - "DIAMETER", "DIASWEL", 32, "Diameter", "SWELLING", + "DIAMETER", "DIASWEL", 32, "Diameter", "SWELLING" ) ``` @@ -542,7 +543,7 @@ adsl <- adsl %>% adface <- derive_vars_merged( dataset = adface, dataset_add = select(adsl, !!!negate_vars(adsl_vars)), - by_vars = exprs(STUDYID, USUBJID) + by_vars = get_admiral_option("subject_keys") ) ``` diff --git a/vignettes/adis.Rmd b/vignettes/adis.Rmd index c568b655..5c49c8d4 100644 --- a/vignettes/adis.Rmd +++ b/vignettes/adis.Rmd @@ -85,6 +85,7 @@ library(admiraldev) library(admiralvaccine) library(pharmaversesdtm) library(metatools) +library(pharmaversesdtm) # Load source datasets data("is_vaccine") @@ -102,7 +103,7 @@ adsl <- convert_blanks_to_na(admiralvaccine_adsl) ## Combine IS with SUPPIS {#combine_supp} Combine `IS` with its supplemental domain `SUPPIS`. ```{r eval=TRUE} -is_suppis <- combine_supp(is, suppis) +is_suppis <- metatools::combine_supp(is, suppis) ``` @@ -111,7 +112,7 @@ Derive `AVISIT`, `AVISITN`, `ATPT`, `ATPTN` and `ATPTREF` variables. Please, update visit records according to your Study Design/Protocol. For the visit values, please refers to your ADAM SPECIFICATIONS. ```{r eval=TRUE} -adis_avisit <- is_suppis %>% +adis <- is_suppis %>% mutate( AVISITN = as.numeric(VISITNUM), AVISIT = case_when( @@ -120,11 +121,7 @@ adis_avisit <- is_suppis %>% VISITNUM == 30 ~ "Visit 3", VISITNUM == 40 ~ "Visit 4", is.na(VISITNUM) ~ NA_character_ - ) - ) - -adis_atpt <- adis_avisit %>% - mutate( + ), ATPTN = as.numeric(VISITNUM / 10), ATPT = case_when( VISITNUM == 10 ~ "Visit 1 (Day 1)", @@ -143,7 +140,7 @@ adis_atpt <- adis_avisit %>% ```{r, echo=FALSE} dataset_vignette( - adis_atpt, + adis, display_vars = exprs(USUBJID, VISITNUM, ISTEST, ISORRES, AVISIT, AVISITN, ATPT, ATPTN, ATPTREF) ) ``` @@ -166,36 +163,33 @@ If your derivation is different, please adapt. # ADT derivation # Add also PPROTFL from ADSL (to avoid additional merges) in order to derive # PPSRFL at step 11. -adis_adt <- derive_vars_dt( - dataset = adis_atpt, +adis <- derive_vars_dt( + dataset = adis, new_vars_prefix = "A", dtc = ISDTC, highest_imputation = "M", date_imputation = "mid", flag_imputation = "none" -) - -# ADY derivation -# Attach RFSTDTC from ADSL in order to derive ADY -adis_ady <- adis_adt %>% +) %>% derive_vars_merged( dataset_add = adsl, new_vars = exprs(RFSTDTC, PPROTFL), - by_vars = exprs(STUDYID, USUBJID) + by_vars = get_admiral_option("subject_keys") ) %>% mutate( - RFSTDT = as.Date(RFSTDTC) + ADT = as.Date(ADT), + RFSTDTC = as.Date(RFSTDTC) ) %>% + # ADY derivation derive_vars_dy( - reference_date = RFSTDT, + reference_date = RFSTDTC, source_vars = exprs(ADT) - ) %>% - select(-RFSTDT) + ) ``` ```{r, echo=FALSE} dataset_vignette( - adis_ady, + adis, display_vars = exprs(USUBJID, VISITNUM, ISTEST, ISORRES, ISDTC, RFSTDTC, ADT, ADY, PPROTFL) ) ``` @@ -214,28 +208,37 @@ Please, add or remove datasets according to your study needs. # Add also records related to 4fold. # Please, keep or modify PARAM values according to your purposes. -is_log <- adis_ady %>% - mutate(DERIVED = "LOG10") +is_log <- adis %>% + mutate( + DERIVED = "LOG10", + ISSEQ = NA_real_ + ) -is_4fold <- adis_ady %>% - mutate(DERIVED = "4FOLD") +is_4fold <- adis %>% + mutate( + DERIVED = "4FOLD", + ISSEQ = NA_real_ + ) -is_log_4fold <- adis_ady %>% - mutate(DERIVED = "LOG10 4FOLD") +is_log_4fold <- adis %>% + mutate( + DERIVED = "LOG10 4FOLD", + ISSEQ = NA_real_ + ) -adis_der <- bind_rows(adis_ady, is_log, is_4fold, is_log_4fold) %>% - arrange(STUDYID, USUBJID, VISITNUM, ISSEQ, !is.na(DERIVED)) %>% +adis <- bind_rows(adis, is_log, is_4fold, is_log_4fold) %>% + arrange(STUDYID, USUBJID, !is.na(DERIVED), ISSEQ) %>% mutate(DERIVED = if_else(is.na(DERIVED), "ORIG", DERIVED)) -adis_paramcd <- adis_der %>% +adis <- adis %>% mutate( # PARAMCD: for log values, concatenation of L and ISTESTCD. PARAMCD = case_when( DERIVED == "ORIG" ~ ISTESTCD, DERIVED == "LOG10" ~ paste0(ISTESTCD, "L"), DERIVED == "4FOLD" ~ paste0(ISTESTCD, "F"), - # As per CDISC rule, PARAMCD should be 8 charcaters long. Please, adapt if needed + # As per CDISC rule, PARAMCD should be 8 characters long. Please, adapt if needed DERIVED == "LOG10 4FOLD" ~ paste0(substr(ISTESTCD, 1, 6), "LF") ) ) @@ -262,8 +265,8 @@ param_lookup <- tribble( "R0003MLF", "LOG10 4FOLD (R0003MA Antibody)", 34 ) -adis_param_paramn <- derive_vars_merged_lookup( - dataset = adis_paramcd, +adis <- derive_vars_merged_lookup( + dataset = adis, dataset_add = param_lookup, new_vars = exprs(PARAM, PARAMN), by_vars = exprs(PARAMCD) @@ -272,7 +275,7 @@ adis_param_paramn <- derive_vars_merged_lookup( ```{r, echo=FALSE} dataset_vignette( - adis_param_paramn, + adis, display_vars = exprs(USUBJID, VISITNUM, ISTEST, ISORRES, PARAMCD, PARAM, PARAMN) ) ``` @@ -283,7 +286,7 @@ Derive `PARCAT1` and `CUTOFF`x variables. Fake values has been put for `CUTOFF` values. Please, adapt base on your objectives. ```{r eval=TRUE} -adis_parcat1_cutoff <- adis_param_paramn %>% +adis <- adis %>% mutate( PARCAT1 = ISCAT, # Please, define your additional cutoff values. Delete if not needed. @@ -294,7 +297,7 @@ adis_parcat1_cutoff <- adis_param_paramn %>% ```{r, echo=FALSE} dataset_vignette( - adis_parcat1_cutoff, + adis, display_vars = exprs(USUBJID, VISITNUM, ISTEST, ISORRES, PARCAT1, CUTOFF02, CUTOFF03) ) ``` @@ -333,7 +336,7 @@ Later you can find `SERCAT1/N` and `DTYPE` derivations. result is below Lower Limit of Quantitation. ```{r eval=TRUE} -adis_or <- adis_parcat1_cutoff %>% +adis_or <- adis %>% filter(DERIVED == "ORIG") %>% derive_var_aval_adis( lower_rule = ISLLOQ / 2, @@ -342,7 +345,7 @@ adis_or <- adis_parcat1_cutoff %>% round = 2 ) -adis_log_or <- adis_parcat1_cutoff %>% +adis_log_or <- adis %>% filter(DERIVED == "LOG10") %>% derive_var_aval_adis( lower_rule = log10(ISLLOQ / 2), @@ -351,7 +354,7 @@ adis_log_or <- adis_parcat1_cutoff %>% round = 2 ) -adis_4fold <- adis_parcat1_cutoff %>% +adis_4fold <- adis %>% filter(DERIVED == "4FOLD") %>% derive_var_aval_adis( lower_rule = ISLLOQ, @@ -360,7 +363,7 @@ adis_4fold <- adis_parcat1_cutoff %>% round = 2 ) -adis_log_4fold <- adis_parcat1_cutoff %>% +adis_log_4fold <- adis %>% filter(DERIVED == "LOG10 4FOLD") %>% derive_var_aval_adis( lower_rule = log10(ISLLOQ), @@ -369,8 +372,9 @@ adis_log_4fold <- adis_parcat1_cutoff %>% round = 2 ) -adis_aval_sercat1 <- bind_rows(adis_or, adis_log_or, adis_4fold, adis_log_4fold) %>% - mutate( # AVALU derivation (please delete if not needed for your study) +adis <- bind_rows(adis_or, adis_log_or, adis_4fold, adis_log_4fold) %>% + mutate( + # AVALU derivation (please delete if not needed for your study) AVALU = ISSTRESU, # SERCAT1 derivation @@ -391,8 +395,8 @@ param_lookup2 <- tribble( NA_character_, NA_real_ ) -adis_sercat1n <- derive_vars_merged_lookup( - dataset = adis_aval_sercat1, +adis <- derive_vars_merged_lookup( + dataset = adis, dataset_add = param_lookup2, new_vars = exprs(SERCAT1N), by_vars = exprs(SERCAT1) @@ -402,8 +406,8 @@ adis_sercat1n <- derive_vars_merged_lookup( # DTYPE derivation. # Please update code when <,<=,>,>= are present in your lab results (in ISSTRESC) -if (any(names(adis_sercat1n) == "ISULOQ") == TRUE) { - adis_dtype <- adis_sercat1n %>% +if (any(names(adis) == "ISULOQ") == TRUE) { + adis <- adis %>% mutate(DTYPE = case_when( DERIVED %in% c("ORIG", "LOG10") & !is.na(ISLLOQ) & ((ISSTRESN < ISLLOQ) | grepl("<", ISORRES)) ~ "HALFLLOQ", @@ -413,8 +417,8 @@ if (any(names(adis_sercat1n) == "ISULOQ") == TRUE) { )) } -if (any(names(adis_sercat1n) == "ISULOQ") == FALSE) { - adis_dtype <- adis_sercat1n %>% +if (any(names(adis) == "ISULOQ") == FALSE) { + adis <- adis %>% mutate(DTYPE = case_when( DERIVED %in% c("ORIG", "LOG10") & !is.na(ISLLOQ) & ((ISSTRESN < ISLLOQ) | grepl("<", ISORRES)) ~ "HALFLLOQ", @@ -425,7 +429,7 @@ if (any(names(adis_sercat1n) == "ISULOQ") == FALSE) { ```{r, echo=FALSE} dataset_vignette( - adis_dtype, + adis, display_vars = exprs(USUBJID, VISITNUM, ISTEST, ISORRES, AVAL, AVALU, DTYPE, SERCAT1, SERCAT1N) ) ``` @@ -437,25 +441,9 @@ Derive Baseline values for each Subject/Visit and relative flag, `ABLFL`. In a later stage, derive `BASECAT` variable, which represents the base category. Update accordingly. ```{r eval=TRUE} -# BASETYPE derivation -adis_basetype <- derive_basetype_records( - adis_dtype, - basetypes = exprs("VISIT 1" = AVISITN %in% c(10, 30)) -) - -# BASE derivation -adis_base <- derive_var_base( - adis_basetype, - by_vars = exprs(STUDYID, USUBJID, PARAMN), - source_var = AVAL, - new_var = BASE, - filter = VISITNUM == 10 -) - - # ABLFL derivation -adis_ablfl <- restrict_derivation( - adis_base, +adis <- restrict_derivation( + adis, derivation = derive_var_extreme_flag, args = params( by_vars = exprs(STUDYID, USUBJID, PARAMN), @@ -463,13 +451,24 @@ adis_ablfl <- restrict_derivation( new_var = ABLFL, mode = "first" ), - filter = VISITNUM == 10 & !is.na(BASE) + filter = VISITNUM == 10 ) %>% - arrange(STUDYID, USUBJID, !is.na(DERIVED), VISITNUM, PARAMN) + # BASE derivation + derive_var_base( + by_vars = exprs(STUDYID, USUBJID, PARAMN), + source_var = AVAL, + new_var = BASE, + filter = ABLFL == "Y" + ) %>% + # BASETYPE derivation + derive_basetype_records( + basetypes = exprs("VISIT 1" = AVISITN %in% c(10, 30)) + ) %>% + arrange(STUDYID, USUBJID, !is.na(DERIVED), ISSEQ) # BASECAT derivation -adis_basecat <- adis_ablfl %>% +adis <- adis %>% mutate( BASECAT1 = case_when( !grepl("L", PARAMCD) & BASE < 10 ~ "Titer value < 1:10", @@ -482,7 +481,7 @@ adis_basecat <- adis_ablfl %>% ```{r, echo=FALSE} dataset_vignette( - adis_basecat, + adis, display_vars = exprs(USUBJID, VISITNUM, ISTEST, ISORRES, ABLFL, BASE, BASETYPE, BASECAT1) ) ``` @@ -493,28 +492,24 @@ Derive change from baseline values. Derive ratio to base values. ```{r eval=TRUE} -adis_chg <- restrict_derivation( - adis_basecat, +adis <- restrict_derivation(adis, derivation = derive_var_chg, filter = AVISITN > 10 -) - -adis_r2b <- restrict_derivation( - adis_chg, - derivation = derive_var_analysis_ratio, - args = params( - numer_var = AVAL, - denom_var = BASE - ), - filter = AVISITN > 10 ) %>% - arrange(STUDYID, USUBJID, DERIVED, ISSEQ) %>% - select(-DERIVED) + restrict_derivation( + derivation = derive_var_analysis_ratio, + args = params( + numer_var = AVAL, + denom_var = BASE + ), + filter = AVISITN > 10 + ) %>% + arrange(STUDYID, USUBJID, DERIVED, ISSEQ) ``` ```{r, echo=FALSE} dataset_vignette( - adis_r2b, + adis, display_vars = exprs(USUBJID, VISITNUM, ISTEST, ISORRES, CHG, R2BASE) ) ``` @@ -531,8 +526,8 @@ The function returns a relative numeric `CRIT1FN` variable (`1` or `0` if the criterion is met, respectively) and a label `CRIT1` variable (with the text specified in label_var argument). ```{r eval=TRUE} -adis_crit <- derive_vars_crit( - dataset = adis_r2b, +adis <- derive_vars_crit( + dataset = adis, prefix = "CRIT1", crit_label = "Titer >= ISLLOQ", condition = !is.na(AVAL) & !is.na(ISLLOQ), @@ -542,7 +537,7 @@ adis_crit <- derive_vars_crit( ```{r, echo=FALSE} dataset_vignette( - adis_crit, + adis, display_vars = exprs(USUBJID, VISITNUM, ISTEST, ISORRES, CRIT1, CRIT1FL, CRIT1FN) ) ``` @@ -555,10 +550,10 @@ period_ref <- create_period_dataset( new_vars = exprs(APERSDT = APxxSDT, APEREDT = APxxEDT, TRTA = TRTxxA, TRTP = TRTxxP) ) -adis_trt <- derive_vars_joined( - adis_crit, +adis <- derive_vars_joined( + adis, dataset_add = period_ref, - by_vars = exprs(STUDYID, USUBJID), + by_vars = get_admiral_option("subject_keys"), filter_join = ADT >= APERSDT & ADT <= APEREDT, join_type = "all" ) @@ -566,7 +561,7 @@ adis_trt <- derive_vars_joined( ```{r, echo=FALSE} dataset_vignette( - adis_trt, + adis, display_vars = exprs(USUBJID, VISITNUM, ISTEST, ISORRES, TRTP, TRTA) ) ``` @@ -578,13 +573,13 @@ PPS related objectives. This step could change according to your study needs. ```{r eval=TRUE} -adis_ppsrfl <- adis_trt %>% +adis <- adis %>% mutate(PPSRFL = if_else(VISITNUM %in% c(10, 30) & PPROTFL == "Y", "Y", NA_character_)) ``` ```{r, echo=FALSE} dataset_vignette( - adis_ppsrfl, + adis, display_vars = exprs(USUBJID, VISITNUM, ISTEST, ISORRES, TRTP, TRTA) ) ``` @@ -596,12 +591,12 @@ Attach all `ADAM.ADSL` variables to the is build-in dataset. If you may need to keep only a subset of them, please update accordingly. ```{r eval=TRUE} # Get list of ADSL variables not to be added to ADIS -adsl_vars <- exprs(RFSTDTC, PPROTFL) +vx_adsl_vars <- exprs(RFSTDTC, PPROTFL) adis <- derive_vars_merged( - dataset = adis_ppsrfl, - dataset_add = select(admiralvaccine_adsl, !!!negate_vars(adsl_vars)), - by_vars = exprs(STUDYID, USUBJID) + dataset = adis, + dataset_add = select(adsl, !!!negate_vars(vx_adsl_vars)), + by_vars = get_admiral_option("subject_keys") ) ``` diff --git a/vignettes/adsl.Rmd b/vignettes/adsl.Rmd index 8ca085f6..d4a30cbe 100644 --- a/vignettes/adsl.Rmd +++ b/vignettes/adsl.Rmd @@ -99,13 +99,13 @@ adsl <- dm %>% dataset_add = ex, filter_add = EXLNKGRP == "VACCINATION 1", new_vars = exprs(TRT01A = EXTRT), - by_vars = exprs(STUDYID, USUBJID) + by_vars = get_admiral_option("subject_keys") ) %>% derive_vars_merged( dataset_add = ex, filter_add = EXLNKGRP == "VACCINATION 2", new_vars = exprs(TRT02A = EXTRT), - by_vars = exprs(STUDYID, USUBJID) + by_vars = get_admiral_option("subject_keys") ) ``` @@ -141,7 +141,7 @@ adsl <- adsl %>% new_vars = exprs(TRTSDTM = EXSTDTM), order = exprs(EXSTDTM, EXSEQ), mode = "first", - by_vars = exprs(STUDYID, USUBJID) + by_vars = get_admiral_option("subject_keys") ) %>% derive_vars_merged( dataset_add = ex_ext, @@ -151,7 +151,7 @@ adsl <- adsl %>% new_vars = exprs(TRTEDTM = EXENDTM), order = exprs(EXENDTM, EXSEQ), mode = "last", - by_vars = exprs(STUDYID, USUBJID) + by_vars = get_admiral_option("subject_keys") ) ```