diff --git a/NEWS.md b/NEWS.md index 4f6a2e8..cb99a00 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,6 +7,12 @@ * The argument `dataset_occ` * The argument `lat_vals` +## Various + +- All vignettes and templates in `{admiralophtha}` have been updated to use the `{admiral}` subject keys option rather than + explicitly quoting key variables such as `STUYDID` and `USUBJID`. For instance, a line such as `by_vars = exprs(STUDYID, USUBJID)` + would be replaced by `by_vars = get_admiral_option("subject_keys")` (#226). + # admiralophtha 1.0.0 ## Updates to Templates diff --git a/R/derive_var_bcvacritxfl.R b/R/derive_var_bcvacritxfl.R index 9c98d67..77da845 100644 --- a/R/derive_var_bcvacritxfl.R +++ b/R/derive_var_bcvacritxfl.R @@ -161,7 +161,7 @@ derive_var_bcvacritxfl <- function(dataset, critxfl_index = NULL) { # Input checks assert_vars(crit_var) - assert_data_frame(dataset, required_vars = c(exprs(STUDYID, USUBJID), crit_var)) + assert_data_frame(dataset, required_vars = crit_var) assert_character_scalar(additional_text) assert_integer_scalar(critxfl_index, optional = TRUE) if (!is.null(bcva_ranges)) lapply(bcva_ranges, assert_numeric_vector) diff --git a/R/derive_var_studyeye.R b/R/derive_var_studyeye.R index e961ac4..dee9e90 100644 --- a/R/derive_var_studyeye.R +++ b/R/derive_var_studyeye.R @@ -42,8 +42,8 @@ #' #' derive_var_studyeye(adsl, sc) derive_var_studyeye <- function(dataset_adsl, dataset_sc, sctestcd_value = "FOCID") { - assert_data_frame(dataset_sc, required_vars = exprs(STUDYID, USUBJID, SCTESTCD, SCSTRESC)) - assert_data_frame(dataset_adsl, required_vars = exprs(STUDYID, USUBJID)) + assert_data_frame(dataset_sc, required_vars = exprs(SCTESTCD, SCSTRESC)) + assert_data_frame(dataset_adsl) seye_cat <- function(seye) { case_when( diff --git a/inst/templates/ad_adbcva.R b/inst/templates/ad_adbcva.R index 6754c33..3893766 100644 --- a/inst/templates/ad_adbcva.R +++ b/inst/templates/ad_adbcva.R @@ -112,7 +112,7 @@ adbcva_adslvar <- oe %>% derive_vars_merged( dataset_add = adsl, new_vars = adsl_vars, - by_vars = exprs(STUDYID, USUBJID) + by_vars = get_admiral_option("subject_keys") ) adbcva_aval <- adbcva_adslvar %>% @@ -137,7 +137,10 @@ adbcva_nlogparam <- adbcva_aval %>% adbcva_logparam <- adbcva_nlogparam %>% # Add derived log parameters derive_param_computed( - by_vars = c(exprs(STUDYID, USUBJID, VISIT, VISITNUM, OEDY, OEDTC, AFEYE), adsl_vars), + by_vars = c( + get_admiral_option("subject_keys"), + exprs(VISIT, VISITNUM, OEDY, OEDTC, AFEYE, !!!adsl_vars) + ), parameters = c("SBCVA"), set_values_to = exprs( AVAL = convert_etdrs_to_logmar(AVAL.SBCVA), @@ -148,7 +151,10 @@ adbcva_logparam <- adbcva_nlogparam %>% ) ) %>% derive_param_computed( - by_vars = c(exprs(STUDYID, USUBJID, VISIT, OEDY, OEDTC, AFEYE), adsl_vars), + by_vars = c( + get_admiral_option("subject_keys"), + exprs(VISIT, VISITNUM, OEDY, OEDTC, AFEYE, !!!adsl_vars) + ), parameters = c("FBCVA"), set_values_to = exprs( AVAL = convert_etdrs_to_logmar(AVAL.FBCVA), @@ -195,7 +201,7 @@ adbcva_trtflag <- adbcva_visit %>% derivation = derive_var_extreme_flag, args = params( new_var = ABLFL, - by_vars = exprs(STUDYID, USUBJID, BASETYPE, PARAMCD), + by_vars = c(get_admiral_option("subject_keys"), exprs(BASETYPE, PARAMCD)), order = exprs(ADT, VISITNUM, OESEQ), mode = "last" ), @@ -209,7 +215,7 @@ adbcva_vstflag <- adbcva_trtflag %>% derivation = derive_var_extreme_flag, args = params( new_var = ANL01FL, - by_vars = exprs(USUBJID, PARAMCD, AVISIT, DTYPE), + by_vars = c(get_admiral_option("subject_keys"), exprs(PARAMCD, AVISIT, DTYPE)), order = exprs(ADT, AVAL), mode = "last" ), @@ -220,7 +226,7 @@ adbcva_vstflag <- adbcva_trtflag %>% derivation = derive_var_extreme_flag, args = params( new_var = ANL02FL, - by_vars = exprs(USUBJID, PARAMCD, ABLFL), + by_vars = c(get_admiral_option("subject_keys"), exprs(PARAMCD, ABLFL)), order = exprs(ADT), mode = "last" ), @@ -231,7 +237,7 @@ adbcva_vstflag <- adbcva_trtflag %>% restrict_derivation( derivation = derive_var_extreme_flag, args = params( - by_vars = exprs(USUBJID, PARAMCD), + by_vars = c(get_admiral_option("subject_keys"), exprs(PARAMCD)), order = exprs(AVAL, ADT), new_var = WORS01FL, mode = "first" @@ -243,13 +249,13 @@ adbcva_vstflag <- adbcva_trtflag %>% adbcva_change <- adbcva_vstflag %>% # Calculate BASE derive_var_base( - by_vars = exprs(STUDYID, USUBJID, PARAMCD, BASETYPE), + by_vars = c(get_admiral_option("subject_keys"), exprs(PARAMCD, BASETYPE)), source_var = AVAL, new_var = BASE ) %>% # Calculate BASEC derive_var_base( - by_vars = exprs(STUDYID, USUBJID, PARAMCD, BASETYPE), + by_vars = c(get_admiral_option("subject_keys"), exprs(PARAMCD, BASETYPE)), source_var = AVALC, new_var = BASEC ) %>% @@ -262,7 +268,7 @@ adbcva_change <- adbcva_vstflag %>% adbcva_aseq <- adbcva_change %>% derive_var_obs_number( new_var = ASEQ, - by_vars = exprs(STUDYID, USUBJID), + by_vars = get_admiral_option("subject_keys"), order = exprs(PARAMCD, ADT, AVISITN, VISITNUM, ATPTN), check_type = "error" ) @@ -271,7 +277,7 @@ adbcva_aseq <- adbcva_change %>% adbcva_adsl <- adbcva_aseq %>% derive_vars_merged( dataset_add = select(adsl, !!!negate_vars(adsl_vars)), - by_vars = exprs(STUDYID, USUBJID) + by_vars = get_admiral_option("subject_keys") ) adbcva_crtflag <- adbcva_adsl %>% diff --git a/inst/templates/ad_adoe.R b/inst/templates/ad_adoe.R index 5e4c55e..e3e029d 100644 --- a/inst/templates/ad_adoe.R +++ b/inst/templates/ad_adoe.R @@ -54,7 +54,7 @@ adoe_adslvar <- oe %>% derive_vars_merged( dataset_add = adsl, new_vars = adsl_vars, - by_vars = exprs(STUDYID, USUBJID) + by_vars = get_admiral_option("subject_keys") ) adoe_aval <- adoe_adslvar %>% @@ -111,7 +111,7 @@ adoe_trtflag <- adoe_visit %>% derivation = derive_var_extreme_flag, args = params( new_var = ABLFL, - by_vars = exprs(STUDYID, USUBJID, BASETYPE, PARAMCD), + by_vars = c(get_admiral_option("subject_keys"), exprs(BASETYPE, PARAMCD)), order = exprs(ADT, VISITNUM, OESEQ), mode = "last" ), @@ -125,7 +125,7 @@ adoe_vstflag <- adoe_trtflag %>% derivation = derive_var_extreme_flag, args = params( new_var = ANL01FL, - by_vars = exprs(USUBJID, PARAMCD, AVISIT, DTYPE), + by_vars = c(get_admiral_option("subject_keys"), exprs(PARAMCD, AVISIT, DTYPE)), order = exprs(ADT, AVAL), mode = "last" ), @@ -136,7 +136,7 @@ adoe_vstflag <- adoe_trtflag %>% derivation = derive_var_extreme_flag, args = params( new_var = ANL02FL, - by_vars = exprs(USUBJID, PARAMCD, ABLFL), + by_vars = c(get_admiral_option("subject_keys"), exprs(PARAMCD, ABLFL)), order = exprs(ADT), mode = "last" ), @@ -147,7 +147,7 @@ adoe_vstflag <- adoe_trtflag %>% restrict_derivation( derivation = derive_var_extreme_flag, args = params( - by_vars = exprs(USUBJID, PARAMCD), + by_vars = c(get_admiral_option("subject_keys"), exprs(PARAMCD)), order = exprs(AVAL, ADT), new_var = WORS01FL, mode = "last" @@ -159,13 +159,13 @@ adoe_vstflag <- adoe_trtflag %>% adoe_change <- adoe_vstflag %>% # Calculate BASE derive_var_base( - by_vars = exprs(STUDYID, USUBJID, PARAMCD, BASETYPE), + by_vars = c(get_admiral_option("subject_keys"), exprs(PARAMCD, BASETYPE)), source_var = AVAL, new_var = BASE ) %>% # Calculate BASEC derive_var_base( - by_vars = exprs(STUDYID, USUBJID, PARAMCD, BASETYPE), + by_vars = c(get_admiral_option("subject_keys"), exprs(PARAMCD, BASETYPE)), source_var = AVALC, new_var = BASEC ) %>% @@ -178,7 +178,7 @@ adoe_change <- adoe_vstflag %>% adoe_aseq <- adoe_change %>% derive_var_obs_number( new_var = ASEQ, - by_vars = exprs(STUDYID, USUBJID), + by_vars = get_admiral_option("subject_keys"), order = exprs(PARAMCD, ADT, AVISITN, VISITNUM, ATPTN), check_type = "error" ) @@ -187,7 +187,7 @@ adoe_aseq <- adoe_change %>% adoe_adsl <- adoe_aseq %>% derive_vars_merged( dataset_add = select(adsl, !!!negate_vars(adsl_vars)), - by_vars = exprs(STUDYID, USUBJID) + by_vars = get_admiral_option("subject_keys") ) # Final Steps, Select final variables and Add labels diff --git a/inst/templates/ad_advfq.R b/inst/templates/ad_advfq.R index ae9e546..399672c 100644 --- a/inst/templates/ad_advfq.R +++ b/inst/templates/ad_advfq.R @@ -43,7 +43,7 @@ advfq_dtdy <- derive_vars_merged( ungroup(qs), dataset_add = adsl, new_vars = adsl_vars, - by_vars = exprs(STUDYID, USUBJID) + by_vars = get_admiral_option("subject_keys") ) %>% ## Calculate ADT, ADY ---- derive_vars_dt( @@ -76,7 +76,10 @@ advfq_aval <- advfq_dtdy %>% advfq_qr01 <- advfq_aval %>% derive_summary_records( dataset_add = advfq_aval, - by_vars = exprs(STUDYID, USUBJID, !!!adsl_vars, PARAMCD, VISITNUM, VISIT, ADT, ADY), + by_vars = c( + get_admiral_option("subject_keys"), + exprs(!!!adsl_vars, PARAMCD, VISITNUM, VISIT, ADT, ADY) + ), filter_add = QSTESTCD == "VFQ1" & !is.na(AVAL), set_values_to = exprs( AVAL = identity(AVAL), @@ -104,7 +107,10 @@ advfq_qr01 <- advfq_aval %>% advfq_qr02 <- advfq_qr01 %>% derive_summary_records( dataset_add = advfq_qr01, - by_vars = exprs(STUDYID, USUBJID, !!!adsl_vars, PARAMCD, VISITNUM, VISIT, ADT, ADY), + by_vars = c( + get_admiral_option("subject_keys"), + exprs(!!!adsl_vars, PARAMCD, VISITNUM, VISIT, ADT, ADY) + ), filter_add = QSTESTCD == "VFQ2" & !is.na(AVAL), set_values_to = exprs( AVAL = identity(AVAL), @@ -132,7 +138,10 @@ advfq_qr02 <- advfq_qr01 %>% advfq_qr03 <- advfq_qr02 %>% derive_summary_records( dataset_add = advfq_qr02, - by_vars = exprs(STUDYID, USUBJID, PARAMCD, !!!adsl_vars, VISITNUM, VISIT, ADT, ADY), + by_vars = c( + get_admiral_option("subject_keys"), + exprs(PARAMCD, !!!adsl_vars, VISITNUM, VISIT, ADT, ADY) + ), filter_add = QSTESTCD == "VFQ3" & !is.na(AVAL), set_values_to = exprs( AVAL = identity(AVAL), @@ -160,7 +169,10 @@ advfq_qr03 <- advfq_qr02 %>% advfq_qr04 <- advfq_qr03 %>% derive_summary_records( dataset_add = advfq_qr03, - by_vars = exprs(STUDYID, USUBJID, PARAMCD, !!!adsl_vars, VISITNUM, VISIT, ADT, ADY), + by_vars = c( + get_admiral_option("subject_keys"), + exprs(PARAMCD, !!!adsl_vars, VISITNUM, VISIT, ADT, ADY) + ), filter_add = QSTESTCD == "VFQ4" & !is.na(AVAL), set_values_to = exprs( AVAL = identity(AVAL), @@ -184,7 +196,10 @@ advfq_qr04 <- advfq_qr03 %>% advfq_qsg01 <- advfq_qr04 %>% derive_summary_records( dataset_add = advfq_qr04, - by_vars = exprs(STUDYID, USUBJID, !!!adsl_vars, VISITNUM, VISIT, ADT, ADY), + by_vars = c( + get_admiral_option("subject_keys"), + exprs(!!!adsl_vars, VISITNUM, VISIT, ADT, ADY) + ), filter_add = PARAMCD %in% c("QR01", "QR02") & !is.na(AVAL), set_values_to = exprs( AVAL = mean(AVAL), @@ -198,7 +213,10 @@ advfq_qsg01 <- advfq_qr04 %>% advfq_qsg02 <- advfq_qsg01 %>% derive_summary_records( dataset_add = advfq_qsg01, - by_vars = exprs(STUDYID, USUBJID, !!!adsl_vars, VISITNUM, VISIT, ADT, ADY), + by_vars = c( + get_admiral_option("subject_keys"), + exprs(!!!adsl_vars, VISITNUM, VISIT, ADT, ADY) + ), filter_add = PARAMCD %in% c("QR03", "QR04") & !is.na(AVAL), set_values_to = exprs( AVAL = mean(AVAL), @@ -213,7 +231,10 @@ advfq_qsg02 <- advfq_qsg01 %>% advfq_qbcs <- advfq_qsg02 %>% derive_summary_records( dataset_add = advfq_qsg02, - by_vars = exprs(STUDYID, USUBJID, !!!adsl_vars, VISITNUM, VISIT, ADT, ADY), + by_vars = c( + get_admiral_option("subject_keys"), + exprs(!!!adsl_vars, VISITNUM, VISIT, ADT, ADY) + ), filter_add = PARAMCD %in% c("QSG01", "QSG02") & !is.na(AVAL), set_values_to = exprs( AVAL = sum(AVAL), @@ -259,7 +280,7 @@ advfq_blfl <- advfq_ontrt %>% restrict_derivation( derivation = derive_var_extreme_flag, args = params( - by_vars = exprs(STUDYID, USUBJID, PARAMCD), + by_vars = c(get_admiral_option("subject_keys"), exprs(PARAMCD)), order = exprs(ADT, VISITNUM, QSSEQ), new_var = ABLFL, mode = "last" @@ -271,7 +292,7 @@ advfq_blfl <- advfq_ontrt %>% advfq_change <- advfq_blfl %>% # Calculate BASE derive_var_base( - by_vars = exprs(STUDYID, USUBJID, PARAMCD), + by_vars = c(get_admiral_option("subject_keys"), exprs(PARAMCD)), source_var = AVAL, new_var = BASE ) %>% @@ -287,7 +308,7 @@ advfq_anlflag <- advfq_change %>% derivation = derive_var_extreme_flag, args = params( new_var = ANL01FL, - by_vars = exprs(USUBJID, PARAMCD, AVISIT), + by_vars = c(get_admiral_option("subject_keys"), exprs(PARAMCD, AVISIT)), order = exprs(ADT, AVAL), mode = "last" ), @@ -299,7 +320,7 @@ advfq_aseq <- advfq_anlflag %>% # Calculate ASEQ derive_var_obs_number( new_var = ASEQ, - by_vars = exprs(STUDYID, USUBJID), + by_vars = get_admiral_option("subject_keys"), order = exprs(PARAMCD, ADT, AVISITN, VISITNUM), check_type = "error" ) %>% @@ -311,7 +332,7 @@ advfq_aseq <- advfq_anlflag %>% advfq_adsl <- advfq_aseq %>% derive_vars_merged( dataset_add = select(adsl, !!!negate_vars(adsl_vars)), - by_vars = exprs(STUDYID, USUBJID) + by_vars = get_admiral_option("subject_keys") ) # Final Steps, Select final variables and Add labels diff --git a/vignettes/adbcva.Rmd b/vignettes/adbcva.Rmd index ae2b23c..75374fa 100644 --- a/vignettes/adbcva.Rmd +++ b/vignettes/adbcva.Rmd @@ -88,7 +88,7 @@ adbcva <- oe %>% derive_vars_merged( dataset_add = adsl, new_vars = adsl_vars, - by_vars = exprs(STUDYID, USUBJID) + by_vars = get_admiral_option("subject_keys") ) ``` @@ -123,7 +123,10 @@ Often ADBCVA datasets contain derived records for BCVA in LogMAR units. This can ```{r} adbcva <- adbcva %>% derive_param_computed( - by_vars = c(exprs(STUDYID, USUBJID, VISIT, VISITNUM, OEDY, OEDTC, AFEYE), adsl_vars), + by_vars = c( + get_admiral_option("subject_keys"), + exprs(VISIT, VISITNUM, OEDY, OEDTC, AFEYE, !!!adsl_vars) + ), parameters = c("SBCVA"), set_values_to = exprs( AVAL = convert_etdrs_to_logmar(AVAL.SBCVA), @@ -134,7 +137,10 @@ adbcva <- adbcva %>% ) ) %>% derive_param_computed( - by_vars = c(exprs(STUDYID, USUBJID, VISIT, OEDY, OEDTC, AFEYE), adsl_vars), + by_vars = c( + get_admiral_option("subject_keys"), + exprs(VISIT, VISITNUM, OEDY, OEDTC, AFEYE, !!!adsl_vars) + ), parameters = c("FBCVA"), set_values_to = exprs( AVAL = convert_etdrs_to_logmar(AVAL.FBCVA), diff --git a/vignettes/adoe.Rmd b/vignettes/adoe.Rmd index 8a746d9..2e7dfbb 100644 --- a/vignettes/adoe.Rmd +++ b/vignettes/adoe.Rmd @@ -90,7 +90,7 @@ adoe <- oe %>% derive_vars_merged( dataset_add = adsl, new_vars = adsl_vars, - by_vars = exprs(STUDYID, USUBJID) + by_vars = get_admiral_option("subject_keys") ) ``` diff --git a/vignettes/advfq.Rmd b/vignettes/advfq.Rmd index 3eff90a..bfbc178 100644 --- a/vignettes/advfq.Rmd +++ b/vignettes/advfq.Rmd @@ -88,7 +88,7 @@ advfq <- derive_vars_merged( qs, dataset_add = adsl, new_vars = adsl_vars, - by_vars = exprs(STUDYID, USUBJID) + by_vars = get_admiral_option("subject_keys") ) ``` @@ -127,7 +127,10 @@ Run this section of code for every question that you need recoding. This gives a advfq <- advfq %>% derive_summary_records( dataset_add = advfq, - by_vars = exprs(STUDYID, USUBJID, !!!adsl_vars, PARAMCD, VISITNUM, VISIT), + by_vars = c( + get_admiral_option("subject_keys"), + exprs(!!!adsl_vars, PARAMCD, VISITNUM, VISIT) + ), filter_add = QSTESTCD == "VFQ1" & !is.na(AVAL), set_values_to = exprs( AVAL = identity(AVAL), @@ -155,7 +158,10 @@ Next, the programmer should create summary records as average of recoded questio advfq <- advfq %>% derive_summary_records( dataset_add = advfq, - by_vars = exprs(STUDYID, USUBJID, !!!adsl_vars, VISITNUM, VISIT, ADT, ADY), + by_vars = c( + get_admiral_option("subject_keys"), + exprs(!!!adsl_vars, VISITNUM, VISIT, ADT, ADY) + ), filter_add = PARAMCD %in% c("QR01", "QR02") & !is.na(AVAL), set_values_to = exprs( AVAL = mean(AVAL), @@ -170,7 +176,7 @@ In most finding ADaMs, an analysis flag is derived to identify the appropriate o In this situation, an analysis flag (e.g. `ANLxxFL`) may be used to choose the appropriate record for analysis. -This flag may be derived using the [`admiral`](https://pharmaverse.github.io/admiral/) function `admiral::derive_var_extreme_flag()`. For this example, we will assume we would like to choose the latest value by `USUBJID`, `PARAMCD` and `AVISIT`. +This flag may be derived using the [`admiral`](https://pharmaverse.github.io/admiral/) function `admiral::derive_var_extreme_flag()`. For this example, we will assume we would like to choose the latest value by our subject keys along with `PARAMCD` and `AVISIT`. ```{r, eval=FALSE} ## ANL01FL: Flag last result within an AVISIT for post-baseline records ---- @@ -179,7 +185,7 @@ advfq <- advfq %>% derivation = derive_var_extreme_flag, args = params( new_var = ANL01FL, - by_vars = exprs(USUBJID, PARAMCD, AVISIT), + by_vars = c(get_admiral_option("subject_keys"), exprs(PARAMCD, AVISIT)), order = exprs(ADT, AVAL), mode = "last" ), @@ -195,7 +201,7 @@ advfq <- advfq %>% # Calculate ASEQ derive_var_obs_number( new_var = ASEQ, - by_vars = exprs(STUDYID, USUBJID), + by_vars = get_admiral_option("subject_keys"), order = exprs(PARAMCD, ADT, AVISITN, VISITNUM), check_type = "error" ) %>% @@ -211,7 +217,7 @@ Once analysis variables have been programmed, variables from ADSL which are requ advfq <- advfq %>% derive_vars_merged( dataset_add = select(adsl, !!!negate_vars(adsl_vars)), - by_vars = exprs(STUDYID, USUBJID) + by_vars = get_admiral_option("subject_keys") ) ``` ## Example Script {#example}