diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 90dbadf3..45bac851 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,6 +1,14 @@ -Thank you for your Pull Request! We have developed this task checklist from the [Development Process Guide](https://pharmaverse.github.io/admiraldev/articles/development_process.html) to help with the final steps of the process. Completing the below tasks helps to ensure our reviewers can maximize their time on your code as well as making sure the admiral codebase remains robust and consistent. +Thank you for your Pull Request! We have developed this task checklist from the +[Development Process +Guide](https://pharmaverse.github.io/admiral/CONTRIBUTING.html#detailed-development-process) +to help with the final steps of the process. Completing the below tasks helps to +ensure our reviewers can maximize their time on your code as well as making sure +the admiral codebase remains robust and consistent. -Please check off each taskbox as an acknowledgment that you completed the task or check off that it is not relevant to your Pull Request. This checklist is part of the Github Action workflows and the Pull Request will not be merged into the `main` branch until you have checked off each task. +Please check off each taskbox as an acknowledgment that you completed the task +or check off that it is not relevant to your Pull Request. This checklist is +part of the Github Action workflows and the Pull Request will not be merged into +the `main` branch until you have checked off each task. - [ ] Place Closes # into the beginning of your Pull Request Title (Use Edit button in top-right if you need to update). Then the issue is closed automatically once it is merged to `main`. - [ ] Code is formatted according to the [tidyverse style guide](https://style.tidyverse.org/). Run `styler::style_file()` to style R and Rmd files diff --git a/DESCRIPTION b/DESCRIPTION index e2fc77b5..980c7646 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -74,3 +74,4 @@ Suggests: DT VignetteBuilder: knitr Config/testthat/edition: 3 +Config/Needs/website: gert diff --git a/NAMESPACE b/NAMESPACE index 265b3115..4bdf6159 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -7,7 +7,6 @@ export(bor_non_crpd) export(bor_pd) export(bor_pr) export(bor_sd) -export(call_aval_fun) export(cb_y) export(cbor_cr) export(cbor_pr) diff --git a/NEWS.md b/NEWS.md index 1041e9e1..0853fb03 100644 --- a/NEWS.md +++ b/NEWS.md @@ -8,6 +8,25 @@ - Website now has button/links to Slack channel and GitHub Issues. (#262) +## Documentation + +- All vignettes and templates were updated to be in line with the changes in +`{admiral}` (see [Breaking +Changes](https://pharmaverse.github.io/admiral/news/index.html#breaking-changes-1-0-0) +for details)(#256). + +## Breaking Changes + +- The `derive_*()` functions were superseded in favor of +`derive_extreme_event()`. Any superseded functions can continue to be used as +demonstrated via the "Basic ADRS" vignette, as they will remain supported and +won't be deprecated in the near future. (#256) + +- The `filter_pd()` function was superseded in favor of `filter_relative()`. (#256) + +- The function `call_aval_fun()`, which was deprecated in admiralonco 0.4.0, +has been removed. (#256) + # admiralonco 0.5.0 ## New Features diff --git a/R/derive_param_bor.R b/R/derive_param_bor.R index 9932aefc..10911356 100644 --- a/R/derive_param_bor.R +++ b/R/derive_param_bor.R @@ -1,5 +1,9 @@ #' Adds a Parameter for Best Overall Response (without confirmation) #' +#' @description +#' `r lifecycle::badge("superseded")` The `derive_param_bor()` function has been +#' superseded in favor of `derive_extreme_event()`. +#' #' Adds a parameter for best overall response, without confirmation, optionally up to #' first progressive disease #' @@ -252,9 +256,8 @@ #' #' @author Stephen Gormley #' -#' @family der_prm_adrs -#' -#' @keywords der_prm_adrs +#' @family superseded +#' @keywords superseded #' #' @return The dataframe passed in the `dataset` argument with additional columns and/or #' rows as set in the `set_values_to` argument. diff --git a/R/derive_param_clinbenefit.R b/R/derive_param_clinbenefit.R index 96af16f9..b67d8e6b 100644 --- a/R/derive_param_clinbenefit.R +++ b/R/derive_param_clinbenefit.R @@ -1,5 +1,9 @@ #' Adds a Parameter for Clinical Benefit #' +#' @description +#' `r lifecycle::badge("superseded")` The `derive_param_clinbenefit()` function +#' has been superseded in favor of `derive_extreme_event()`. +#' #' Adds a parameter for clinical benefit/disease control #' #' @details @@ -114,9 +118,8 @@ #' #' @return The input dataset with a new parameter for clinical benefit #' -#' @family der_prm_adrs -#' -#' @keywords der_prm_adrs +#' @family superseded +#' @keywords superseded #' #' @export #' diff --git a/R/derive_param_confirmed_bor.R b/R/derive_param_confirmed_bor.R index 0e4401cc..bf1af99a 100644 --- a/R/derive_param_confirmed_bor.R +++ b/R/derive_param_confirmed_bor.R @@ -1,5 +1,9 @@ #' Adds a Parameter for Confirmed Best Overall Response #' +#' @description +#' `r lifecycle::badge("superseded")` The `derive_param_confirmed_bor()` +#' function has been superseded in favor of `derive_extreme_event()`. +#' #' Adds a parameter for confirmed best overall response (BOR) #' #' @param dataset Input dataset @@ -187,9 +191,8 @@ #' @return The input dataset with a new parameter for confirmed best overall #' response #' -#' @family der_prm_adrs -#' -#' @keywords der_prm_adrs +#' @family superseded +#' @keywords superseded #' #' @author Stefan Bundfuss #' @@ -419,7 +422,7 @@ derive_param_confirmed_bor <- function(dataset, ADT.join >= ADT + days(!!ref_confirm), filter_join = AVALC == "CR" & all(AVALC.join %in% c("CR", "NE")) & - count_vals(var = AVALC.join, val = "NE") <= !!max_nr_ne + {{ count_vals }}(var = AVALC.join, val = "NE") <= !!max_nr_ne ) %>% mutate(tmp_order = 1) @@ -439,15 +442,15 @@ derive_param_confirmed_bor <- function(dataset, ADT.join >= ADT + days(!!ref_confirm), filter_join = AVALC == "PR" & all(AVALC.join %in% c("CR", "PR", "SD", "NE")) & - count_vals(var = AVALC.join, val = "NE") <= !!max_nr_ne & - count_vals(var = AVALC.join, val = "SD") <= !!max_nr_sd & + {{ count_vals }}(var = AVALC.join, val = "NE") <= !!max_nr_ne & + {{ count_vals }}(var = AVALC.join, val = "SD") <= !!max_nr_sd & ( - min_cond( + {{ min_cond }}( var = ADT.join, cond = AVALC.join == "CR" - ) > max_cond(var = ADT.join, cond = AVALC.join == "PR") | - count_vals(var = AVALC.join, val = "CR") == 0 | - count_vals(var = AVALC.join, val = "PR") == 0 + ) > {{ max_cond }}(var = ADT.join, cond = AVALC.join == "PR") | + {{ count_vals }}(var = AVALC.join, val = "CR") == 0 | + {{ count_vals }}(var = AVALC.join, val = "PR") == 0 ) ) %>% mutate(tmp_order = 2) diff --git a/R/derive_param_confirmed_resp.R b/R/derive_param_confirmed_resp.R index 6629db52..26c0b6ee 100644 --- a/R/derive_param_confirmed_resp.R +++ b/R/derive_param_confirmed_resp.R @@ -1,5 +1,9 @@ #' Adds a Parameter for Confirmed Response #' +#' @description +#' `r lifecycle::badge("superseded")` The `derive_param_confirmed_resp()` +#' function has been superseded in favor of `derive_extreme_event()`. +#' #' Adds a parameter for confirmed response #' #' @param dataset Input dataset @@ -135,9 +139,8 @@ #' #' @return The input dataset with a new parameter for confirmed response #' -#' @family der_prm_adrs -#' -#' @keywords der_prm_adrs +#' @family superseded +#' @keywords superseded #' #' @author Stefan Bundfuss #' @@ -351,7 +354,7 @@ derive_param_confirmed_resp <- function(dataset, ADT.join >= ADT + days(!!ref_confirm), filter_join = AVALC == "CR" & all(AVALC.join %in% c("CR", "NE")) & - count_vals(var = AVALC.join, val = "NE") <= !!max_nr_ne + {{ count_vals }}(var = AVALC.join, val = "NE") <= !!max_nr_ne ) %>% mutate( AVALC = "Y" @@ -373,15 +376,15 @@ derive_param_confirmed_resp <- function(dataset, ADT.join >= ADT + days(!!ref_confirm), filter_join = AVALC == "PR" & all(AVALC.join %in% c("CR", "PR", "SD", "NE")) & - count_vals(var = AVALC.join, val = "NE") <= !!max_nr_ne & - count_vals(var = AVALC.join, val = "SD") <= !!max_nr_sd & + {{ count_vals }}(var = AVALC.join, val = "NE") <= !!max_nr_ne & + {{ count_vals }}(var = AVALC.join, val = "SD") <= !!max_nr_sd & ( - min_cond( + {{ min_cond }}( var = ADT.join, cond = AVALC.join == "CR" - ) > max_cond(var = ADT.join, cond = AVALC.join == "PR") | - count_vals(var = AVALC.join, val = "CR") == 0 | - count_vals(var = AVALC.join, val = "PR") == 0 + ) > {{ max_cond }}(var = ADT.join, cond = AVALC.join == "PR") | + {{ count_vals }}(var = AVALC.join, val = "CR") == 0 | + {{ count_vals }}(var = AVALC.join, val = "PR") == 0 ) ) %>% mutate( diff --git a/R/derive_param_response.R b/R/derive_param_response.R index e5fe61b1..0cd7eeda 100644 --- a/R/derive_param_response.R +++ b/R/derive_param_response.R @@ -1,6 +1,10 @@ #' Adds a Parameter Indicating If a Subject Had a Response before Progressive #' Disease #' +#' @description +#' `r lifecycle::badge("superseded")` The `derive_param_response()` function has +#' been superseded in favor of `derive_extreme_event()`. +#' #' Adds a parameter indicating if a response has been observed. #' If a response has been observed, `AVALC` is set to "Y", `AVAL` to 1 and `ADT` #' is set to the @@ -104,9 +108,8 @@ #' @return The input dataset with a new parameter indicating if and when a #' response occurred #' -#' @family der_prm_adrs -#' -#' @keywords der_prm_adrs +#' @family superseded +#' @keywords superseded #' #' @export #' diff --git a/R/filter_pd.R b/R/filter_pd.R index 4a39c479..c788b4b0 100644 --- a/R/filter_pd.R +++ b/R/filter_pd.R @@ -1,5 +1,9 @@ #' Filter up to First PD (Progressive Disease) Date #' +#' @description +#' `r lifecycle::badge("superseded")` The `filter_pd()` function has been +#' superseded in favor of `filter_relative()`. +#' #' Filter a dataset to only include the source parameter records up to and #' including the first PD (progressive disease). These records are passed to #' downstream derivations regarding responses such as BOR (best overall @@ -45,8 +49,8 @@ #' #' @export #' -#' @keywords utils_fil -#' @family utils_fil +#' @family superseded +#' @keywords superseded #' #' @examples #' diff --git a/R/response_sources.R b/R/response_sources.R index bae3005e..c79ed56e 100644 --- a/R/response_sources.R +++ b/R/response_sources.R @@ -172,7 +172,7 @@ crsp_y_cr <- event_joined( join_vars = exprs(AVALC, ADT), join_type = "after", order = exprs(ADT), - first_cond = AVALC.join == "CR" & + first_cond_upper = AVALC.join == "CR" & ADT.join >= ADT + days(28), condition = AVALC == "CR" & all(AVALC.join %in% c("CR", "NE")) & @@ -193,7 +193,7 @@ crsp_y_pr <- event_joined( join_vars = exprs(AVALC, ADT), join_type = "after", order = exprs(ADT), - first_cond = AVALC.join %in% c("CR", "PR") & + first_cond_upper = AVALC.join %in% c("CR", "PR") & ADT.join >= ADT + days(28), condition = AVALC == "PR" & all(AVALC.join %in% c("CR", "PR", "NE")) & @@ -221,7 +221,7 @@ cbor_cr <- event_joined( dataset_name = "ovr", join_vars = exprs(AVALC, ADT), join_type = "after", - first_cond = AVALC.join == "CR" & + first_cond_upper = AVALC.join == "CR" & ADT.join >= ADT + 28, condition = AVALC == "CR" & all(AVALC.join %in% c("CR", "NE")) & @@ -242,7 +242,7 @@ cbor_pr <- event_joined( dataset_name = "ovr", join_vars = exprs(AVALC, ADT), join_type = "after", - first_cond = AVALC.join %in% c("CR", "PR") & + first_cond_upper = AVALC.join %in% c("CR", "PR") & ADT.join >= ADT + 28, condition = AVALC == "PR" & all(AVALC.join %in% c("CR", "PR", "NE")) & diff --git a/R/utils.R b/R/utils.R deleted file mode 100644 index 5d73cb01..00000000 --- a/R/utils.R +++ /dev/null @@ -1,58 +0,0 @@ -#' Creates `AVAL` from `AVALC` by Calling User Function -#' -#' @description -#' `r lifecycle::badge("deprecated")` -#' -#' This function is *deprecated*, please use -#' `admiraldev::process_set_values_to()` instead. -#' -#' Create `AVAL` from `AVALC` by calling a function provided by the user. If -#' calling the function fails, the error is caught and a helpful error message -#' provided. -#' -#' @param dataset Input dataset -#' -#' The variable `AVALC` is expected. -#' -#' *Permitted Values*: a dataframe -#' -#' @param aval_fun Function returning the `AVALC` values -#' -#' The specified function must expect one argument expecting a character -#' vector and must return a numeric vector. -#' -#' *Permitted Values*: a function -#' -#' @details The new variable `AVAL` is set to `aval_fun(AVALC)`. -#' -#' @author Stefan Bundfuss -#' -#' @returns The input dataset with `AVAL` added -#' -#' @keywords deprecated -#' @family deprecated -#' -#' @export -call_aval_fun <- function(dataset, - aval_fun) { - assert_data_frame(dataset, required_vars = exprs(AVALC)) - assert_function(aval_fun) - - deprecate_warn("0.4.0", "call_aval_fun()", "admiraldev::process_set_values_to()") - - tryCatch( - mutate( - dataset, - AVAL = aval_fun(AVALC) - ), - error = function(cnd) { - abort( - paste0( - "Assigning new AVAL records with aval_fun (`AVAL = aval_fun(AVALC)`) has failed.\n", - "Error message:\n ", - cnd - ) - ) - } - ) -} diff --git a/_pkgdown.yml b/_pkgdown.yml index af54376b..4a6b60fa 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -14,17 +14,14 @@ repo: user: https://github.com/ news: cran_dates: true -reference: - - title: Derivations for Adding Parameters - - subtitle: ADRS-specific - desc: Parameter Derivation Functions helpful for building the ADRS dataset - - contents: - - has_keyword("der_prm_adrs") +development: + mode: auto + +reference: - - title: Advanced Functions - - subtitle: Pre-Defined Objects - desc: 'Objects defined by {admiralonco} that can be used as input for derivations' + - title: Pre-Defined Objects + desc: 'Objects defined by `{admiralonco}` that can be used as input for derivations' - contents: - has_keyword("source_specifications") @@ -37,27 +34,25 @@ reference: - contents: - has_keyword('utils_ds_chk') - - subtitle: Utilities for Filtering Observations - - contents: - - has_keyword('utils_fil') - - title: Example Datasets desc: You can run `admiral::use_ad_template()` to produce additional datasets - contents: - has_keyword('datasets') - - title: Relocated/Deprecated - - subtitle: Functions moved to another admiraldev package - - contents: - - has_keyword("move_adm_dev") - - subtitle: Deprecated - - contents: - - has_keyword("deprecated") + - title: Superseded + desc: | + Superseded functions have been replaced with more flexible functions that + allow for construction of more diverse endpoints for a wider array of + oncology indications, beyond solid tumor/RECIST. However, we will not be + removing these functions from `{admiralonco}` in the near future and they + will continue to be supported. + contents: + - has_keyword("superseded") navbar: structure: left: [getstarted, reference, articles, news] - right: [search, slack, newissue, github] + right: [search, slack, history, newissue, github] components: getstarted: text: Get Started @@ -80,6 +75,10 @@ navbar: href: articles/adtr.html - text: Creating and Using New Anti-Cancer Start Date href: articles/nactdt.html + history: + icon: fa-history + href: articles/website-versions.html + aria-label: Previous Release Websites slack: icon: fa-slack href: https://app.slack.com/client/T028PB489D3/C02M8KN8269 diff --git a/inst/WORDLIST b/inst/WORDLIST index 1f0971bb..3bc9f86a 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -1,39 +1,37 @@ -ACCB ADRS ADSL ADTR ADTTE ADaM ADaMs -BCP +BDS BICR BOR Biologics -CBCP CDISC CRF GlaxoSmithKline Hoffmann +IBCP +ICBCP +ILSTA +IMDIS IMWG +IOVRB IRF LLC -LSTA Myeloma -OVRB PFS Pre RECIST SDTM SDTMs -adrs censorings chk datetime -der ds durations evaluable -fil fmt funder iCPD @@ -41,7 +39,6 @@ iRECIST myeloma pharmaverse pre -prm quosures radiological rda diff --git a/inst/templates/ad_adrs.R b/inst/templates/ad_adrs.R index 0a75f46e..16d5526d 100644 --- a/inst/templates/ad_adrs.R +++ b/inst/templates/ad_adrs.R @@ -6,6 +6,9 @@ library(admiral) library(admiralonco) library(pharmaversesdtm) # Contains example datasets from the CDISC pilot project +# pharmaverseadam contains example datasets generated from the CDISC pilot +# project SDTM ran through admiral templates +library(pharmaverseadam) library(dplyr) library(lubridate) library(stringr) @@ -16,11 +19,10 @@ library(stringr) # as needed and assign to the variables below. # For illustration purposes read in pharmaverse test data -data("admiral_adsl") +data("adsl") data("rs_onco_recist") data("tu_onco_recist") -adsl <- admiral_adsl rs <- rs_onco_recist tu <- tu_onco_recist @@ -51,7 +53,7 @@ adrs <- adrs %>% PARAM = "Overall Response by Investigator", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1" + PARCAT3 = "RECIST 1.1" ) # Date imputations - here we impute missing day to last possible date @@ -75,12 +77,24 @@ adrs <- adrs %>% # parameter derivations - here only valid assessments and those occurring on or # after randomization date, if there is more than one assessment per date the # worst one is flagged +worst_resp <- function(arg) { + case_when( + arg == "NE" ~ 1, + arg == "CR" ~ 2, + arg == "PR" ~ 3, + arg == "SD" ~ 4, + arg == "NON-CR/NON-PD" ~ 5, + arg == "PD" ~ 6, + TRUE ~ 0 + ) +} + adrs <- adrs %>% restrict_derivation( derivation = derive_var_extreme_flag, args = params( by_vars = exprs(STUDYID, USUBJID, ADT), - order = exprs(AVAL, RSSEQ), + order = exprs(worst_resp(AVALC), RSSEQ), new_var = ANL01FL, mode = "last" ), @@ -134,12 +148,13 @@ adrs <- adrs %>% order = exprs(ADT, RSSEQ), mode = "first", exist_flag = AVALC, + false_value = "N", set_values_to = exprs( PARAMCD = "PD", PARAM = "Disease Progression by Investigator", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = yn_to_numeric(AVALC), ANL01FL = "Y" ) @@ -149,7 +164,8 @@ adrs <- adrs %>% adrs <- adrs %>% derive_extreme_event( by_vars = exprs(STUDYID, USUBJID), - order = exprs(ADT), + order = exprs(event_nr, ADT), + tmp_event_nr_var = event_nr, mode = "first", events = list(rsp_y, no_data_n), source_datasets = list( @@ -161,7 +177,7 @@ adrs <- adrs %>% PARAM = "Response by Investigator (confirmation not required)", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = yn_to_numeric(AVALC), ANL01FL = "Y" ) @@ -171,20 +187,20 @@ adrs <- adrs %>% adrs <- adrs %>% derive_extreme_event( by_vars = exprs(STUDYID, USUBJID), - order = exprs(desc(AVALC), ADT), + order = exprs(desc(AVALC), ADT, event_nr), + tmp_event_nr_var = event_nr, mode = "first", events = list(rsp_y, cb_y, no_data_n), source_datasets = list( ovr = ovr, adsl = adsl ), - ignore_event_order = TRUE, set_values_to = exprs( PARAMCD = "CB", PARAM = "Clinical Benefit by Investigator (confirmation for response not required)", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = yn_to_numeric(AVALC), ANL01FL = "Y" ), @@ -199,7 +215,8 @@ adrs <- adrs %>% adrs <- adrs %>% derive_extreme_event( by_vars = exprs(STUDYID, USUBJID), - order = exprs(ADT), + order = exprs(event_nr, ADT), + tmp_event_nr_var = event_nr, mode = "first", source_datasets = list( ovr = ovr, @@ -211,7 +228,7 @@ adrs <- adrs %>% PARAM = "Best Overall Response by Investigator (confirmation not required)", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = aval_resp(AVALC), ANL01FL = "Y" ) @@ -225,12 +242,13 @@ adrs <- adrs %>% by_vars = exprs(STUDYID, USUBJID), filter_add = PARAMCD == "BOR" & AVALC %in% c("CR", "PR"), exist_flag = AVALC, + false_value = "N", set_values_to = exprs( PARAMCD = "BCP", PARAM = "Best Overall Response of CR/PR by Investigator (confirmation not required)", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = yn_to_numeric(AVALC), ANL01FL = "Y" ) @@ -240,20 +258,20 @@ adrs <- adrs %>% adrs <- adrs %>% derive_extreme_event( by_vars = exprs(STUDYID, USUBJID), - order = exprs(desc(AVALC), ADT), + order = exprs(desc(AVALC), ADT, event_nr), + tmp_event_nr_var = event_nr, mode = "first", source_datasets = list( ovr = ovr, adsl = adsl ), events = list(crsp_y_cr, crsp_y_pr, no_data_n), - ignore_event_order = TRUE, set_values_to = exprs( PARAMCD = "CRSP", PARAM = "Confirmed Response by Investigator", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = yn_to_numeric(AVALC), ANL01FL = "Y" ) @@ -262,30 +280,30 @@ adrs <- adrs %>% adrs <- adrs %>% derive_extreme_event( by_vars = exprs(STUDYID, USUBJID), - order = exprs(desc(AVALC), ADT), + order = exprs(desc(AVALC), ADT, event_nr), + tmp_event_nr_var = event_nr, mode = "first", events = list(crsp_y_cr, crsp_y_pr, cb_y, no_data_n), source_datasets = list( ovr = ovr, adsl = adsl ), - ignore_event_order = TRUE, set_values_to = exprs( PARAMCD = "CCB", PARAM = "Confirmed Clinical Benefit by Investigator", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = yn_to_numeric(AVALC), ANL01FL = "Y" - ), - check_type = "none" + ) ) adrs <- adrs %>% derive_extreme_event( by_vars = exprs(STUDYID, USUBJID), - order = exprs(ADT), + order = exprs(event_nr, ADT), + tmp_event_nr_var = event_nr, mode = "first", events = list(cbor_cr, cbor_pr, bor_sd, bor_non_crpd, bor_pd, bor_ne, no_data_missing), source_datasets = list( @@ -297,7 +315,7 @@ adrs <- adrs %>% PARAM = "Best Confirmed Overall Response by Investigator", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = aval_resp(AVALC), ANL01FL = "Y" ) @@ -308,12 +326,13 @@ adrs <- adrs %>% by_vars = exprs(STUDYID, USUBJID), filter_add = PARAMCD == "CBOR" & AVALC %in% c("CR", "PR"), exist_flag = AVALC, + false_value = "N", set_values_to = exprs( PARAMCD = "CBCP", PARAM = "Best Confirmed Overall Response of CR/PR by Investigator", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = yn_to_numeric(AVALC), ANL01FL = "Y" ) @@ -330,6 +349,7 @@ adrs <- adrs %>% by_vars = exprs(STUDYID, USUBJID), filter_add = !is.na(DTHDT), exist_flag = AVALC, + false_value = "N", set_values_to = exprs( PARAMCD = "DEATH", PARAM = "Death", @@ -355,7 +375,7 @@ adrs <- adrs %>% PARAM = "Last Disease Assessment by Investigator", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", ANL01FL = "Y" ) ) @@ -375,7 +395,7 @@ adrs <- adrs %>% PARAMCD = "MDIS", PARAM = "Measurable Disease at Baseline by Investigator", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = yn_to_numeric(AVALC), ANL01FL = "Y" ) diff --git a/inst/templates/ad_adrs_basic.R b/inst/templates/ad_adrs_basic.R index a77cea5d..c02ed784 100644 --- a/inst/templates/ad_adrs_basic.R +++ b/inst/templates/ad_adrs_basic.R @@ -14,6 +14,9 @@ library(admiral) library(admiralonco) library(pharmaversesdtm) # Contains example datasets from the CDISC pilot project +# pharmaverseadam contains example datasets generated from the CDISC pilot +# project SDTM ran through admiral templates +library(pharmaverseadam) library(dplyr) library(lubridate) library(stringr) @@ -24,11 +27,10 @@ library(stringr) # as needed and assign to the variables below. # For illustration purposes read in pharmaverse test data -data("admiral_adsl") +data("adsl") data("rs_onco_recist") data("tu_onco_recist") -adsl <- admiral_adsl rs <- rs_onco_recist tu <- tu_onco_recist @@ -59,7 +61,7 @@ adrs <- adrs %>% PARAM = "Overall Response by Investigator", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1" + PARCAT3 = "RECIST 1.1" ) # Date imputations - here we impute missing day to last possible date @@ -83,12 +85,24 @@ adrs <- adrs %>% # parameter derivations - here only valid assessments and those occurring on or # after randomization date, if there is more than one assessment per date the # worst one is flagged +worst_resp <- function(arg) { + case_when( + arg == "NE" ~ 1, + arg == "CR" ~ 2, + arg == "PR" ~ 3, + arg == "SD" ~ 4, + arg == "NON-CR/NON-PD" ~ 5, + arg == "PD" ~ 6, + TRUE ~ 0 + ) +} + adrs <- adrs %>% restrict_derivation( derivation = derive_var_extreme_flag, args = params( by_vars = exprs(STUDYID, USUBJID, ADT), - order = exprs(AVAL, RSSEQ), + order = exprs(worst_resp(AVALC), RSSEQ), new_var = ANL01FL, mode = "last" ), @@ -107,12 +121,13 @@ adrs <- adrs %>% order = exprs(ADT, RSSEQ), mode = "first", exist_flag = AVALC, + false_value = "N", set_values_to = exprs( PARAMCD = "PD", PARAM = "Disease Progression by Investigator", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = yn_to_numeric(AVALC), ANL01FL = "Y" ) @@ -137,7 +152,7 @@ adrs <- adrs %>% PARAM = "Response by Investigator (confirmation not required)", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = yn_to_numeric(AVALC), ANL01FL = "Y" ) @@ -165,7 +180,7 @@ adrs <- adrs %>% PARAM = "Clinical Benefit by Investigator (confirmation for response not required)", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = yn_to_numeric(AVALC), ANL01FL = "Y" ) @@ -185,7 +200,7 @@ adrs <- adrs %>% PARAM = "Best Overall Response by Investigator (confirmation not required)", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = aval_resp(AVALC), ANL01FL = "Y" ) @@ -201,12 +216,13 @@ adrs <- adrs %>% order = exprs(ADT, RSSEQ), mode = "first", exist_flag = AVALC, + false_value = "N", set_values_to = exprs( PARAMCD = "BCP", PARAM = "Best Overall Response of CR/PR by Investigator (confirmation not required)", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = yn_to_numeric(AVALC), ANL01FL = "Y" ) @@ -225,7 +241,7 @@ adrs <- adrs %>% PARAM = "Confirmed Response by Investigator", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = yn_to_numeric(AVALC), ANL01FL = "Y" ) @@ -251,7 +267,7 @@ adrs <- adrs %>% PARAM = "Confirmed Clinical Benefit by Investigator", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = yn_to_numeric(AVALC), ANL01FL = "Y" ) @@ -269,7 +285,7 @@ adrs <- adrs %>% PARAM = "Best Confirmed Overall Response by Investigator", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = aval_resp(AVALC), ANL01FL = "Y" ) @@ -282,12 +298,13 @@ adrs <- adrs %>% order = exprs(ADT, RSSEQ), mode = "first", exist_flag = AVALC, + false_value = "N", set_values_to = exprs( PARAMCD = "CBCP", PARAM = "Best Confirmed Overall Response of CR/PR by Investigator", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = yn_to_numeric(AVALC), ANL01FL = "Y" ) @@ -304,6 +321,7 @@ adrs <- adrs %>% by_vars = exprs(STUDYID, USUBJID), filter_add = !is.na(DTHDT), exist_flag = AVALC, + false_value = "N", set_values_to = exprs( PARAMCD = "DEATH", PARAM = "Death", @@ -329,7 +347,7 @@ adrs <- adrs %>% PARAM = "Last Disease Assessment by Investigator", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", ANL01FL = "Y" ) ) @@ -349,7 +367,7 @@ adrs <- adrs %>% PARAMCD = "MDIS", PARAM = "Measurable Disease at Baseline by Investigator", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = yn_to_numeric(AVALC), ANL01FL = "Y" ) diff --git a/inst/templates/ad_adtr.R b/inst/templates/ad_adtr.R index 516f75fe..abf7b7c8 100644 --- a/inst/templates/ad_adtr.R +++ b/inst/templates/ad_adtr.R @@ -6,6 +6,9 @@ library(admiral) library(admiralonco) library(pharmaversesdtm) # Contains example datasets from the CDISC pilot project +# pharmaverseadam contains example datasets generated from the CDISC pilot +# project SDTM ran through admiral templates +library(pharmaverseadam) library(dplyr) library(lubridate) library(stringr) @@ -15,11 +18,10 @@ library(stringr) # Use e.g. haven::read_sas to read in .sas7bdat, or other suitable functions # as needed and assign to the variables below. # For illustration purposes read in pharmaverse test data -data("admiral_adsl") +data("adsl") data("rs_onco_recist") data("tu_onco_recist") data("tr_onco_recist") -adsl <- admiral_adsl tu <- tu_onco_recist tr <- tr_onco_recist rs <- rs_onco_recist @@ -107,26 +109,27 @@ adtr <- bind_rows( mutate( PARCAT1 = "Target Lesion(s)", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = TRSTRESN, ANL01FL = if_else(!is.na(AVAL), "Y", NA_character_) ) %>% select(-tmp_lesion_nr) # Derive parameter for sum of diameter (SDIAM) ---- -adtr_sum <- get_summary_records( - adtr, +adtr_sum <- derive_summary_records( + dataset_add = adtr, by_vars = exprs(STUDYID, USUBJID, !!!adsl_vars, AVISIT, AVISITN), - filter = (str_starts(PARAMCD, "LDIAM") & TULOCGR1 == "NON-NODAL") | + filter_add = (str_starts(PARAMCD, "LDIAM") & TULOCGR1 == "NON-NODAL") | (str_starts(PARAMCD, "NLDIAM") & TULOCGR1 == "NODAL"), - analysis_var = AVAL, - summary_fun = function(x) sum(x, na.rm = TRUE), set_values_to = exprs( + AVAL = sum(AVAL, na.rm = TRUE), + ADY = min(ADY, na.rm = TRUE), + ADT = min(ADT, na.rm = TRUE), PARAMCD = "SDIAM", PARAM = "Target Lesions Sum of Diameters by Investigator", PARCAT1 = "Target Lesion(s)", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1" + PARCAT3 = "RECIST 1.1" ) ) @@ -138,44 +141,19 @@ adtr_sum <- adtr_sum %>% filter_add = AVISIT == "BASELINE" & ((str_starts(PARAMCD, "LDIAM") & TULOCGR1 == "NON-NODAL") | (str_starts(PARAMCD, "NLDIAM") & TULOCGR1 == "NODAL")), - new_var = LSEXP, - analysis_var = TRLNKID, - summary_fun = function(x) paste(sort(x), collapse = ", ") + new_vars = exprs(LSEXP = paste(sort(TRLNKID), collapse = ", ")) ) %>% derive_var_merged_summary( dataset_add = adtr, by_vars = exprs(USUBJID, AVISIT), filter_add = ((str_starts(PARAMCD, "LDIAM") & TULOCGR1 == "NON-NODAL") | (str_starts(PARAMCD, "NLDIAM") & TULOCGR1 == "NODAL")) & ANL01FL == "Y", - new_var = LSASS, - analysis_var = TRLNKID, - summary_fun = function(x) paste(sort(x), collapse = ", ") + new_vars = exprs(LSASS = paste(sort(TRLNKID), collapse = ", ")) ) %>% mutate( ANL01FL = if_else(LSEXP == LSASS, "Y", NA_character_) ) -# Derive timing variables for sums (ADT, ADY) ---- -adtr_sum <- adtr_sum %>% - derive_var_merged_summary( - dataset_add = adtr, - by_vars = exprs(USUBJID, AVISIT), - filter_add = (str_starts(PARAMCD, "LDIAM") & TULOCGR1 == "NON-NODAL") | - (str_starts(PARAMCD, "NLDIAM") & TULOCGR1 == "NODAL"), - new_var = ADY, - analysis_var = ADY, - summary_fun = function(x) min(x, na.rm = TRUE) - ) %>% - derive_var_merged_summary( - dataset_add = adtr, - by_vars = exprs(USUBJID, AVISIT), - filter_add = (str_starts(PARAMCD, "LDIAM") & TULOCGR1 == "NON-NODAL") | - (str_starts(PARAMCD, "NLDIAM") & TULOCGR1 == "NODAL"), - new_var = ADT, - analysis_var = ADT, - summary_fun = function(x) min(x, na.rm = TRUE) - ) - # Derive baseline (ABLFL, BASE) ---- adtr_sum <- adtr_sum %>% restrict_derivation( @@ -200,6 +178,7 @@ adtr_sum <- adtr_sum %>% order = exprs(AVAL), new_vars = exprs(NADIR = AVAL), join_vars = exprs(ADY), + join_type = "all", filter_add = ANL01FL == "Y", filter_join = ADY.join < ADY, mode = "first", diff --git a/inst/templates/ad_adtte.R b/inst/templates/ad_adtte.R index 80d0b470..e5b0debf 100644 --- a/inst/templates/ad_adtte.R +++ b/inst/templates/ad_adtte.R @@ -5,6 +5,9 @@ # Input: adsl, adrs, tte_source objects library(admiral) library(admiralonco) +# pharmaverseadam contains example datasets generated from the CDISC pilot +# project SDTM ran through admiral templates +library(pharmaverseadam) library(dplyr) library(lubridate) @@ -14,11 +17,10 @@ library(lubridate) # as needed and assign to the variables below. # For illustration purposes read in admiral test data -data("admiral_adsl") -data("admiral_adrs") +data("adsl") +data("adrs_onco") -adsl <- admiral_adsl -adrs <- admiral_adrs +adrs <- adrs_onco # Derivations ---- diff --git a/man/call_aval_fun.Rd b/man/call_aval_fun.Rd deleted file mode 100644 index d0c2f761..00000000 --- a/man/call_aval_fun.Rd +++ /dev/null @@ -1,43 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utils.R -\name{call_aval_fun} -\alias{call_aval_fun} -\title{Creates \code{AVAL} from \code{AVALC} by Calling User Function} -\usage{ -call_aval_fun(dataset, aval_fun) -} -\arguments{ -\item{dataset}{Input dataset - -The variable \code{AVALC} is expected. - -\emph{Permitted Values}: a dataframe} - -\item{aval_fun}{Function returning the \code{AVALC} values - -The specified function must expect one argument expecting a character -vector and must return a numeric vector. - -\emph{Permitted Values}: a function} -} -\value{ -The input dataset with \code{AVAL} added -} -\description{ -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} - -This function is \emph{deprecated}, please use -\code{admiraldev::process_set_values_to()} instead. - -Create \code{AVAL} from \code{AVALC} by calling a function provided by the user. If -calling the function fails, the error is caught and a helpful error message -provided. -} -\details{ -The new variable \code{AVAL} is set to \code{aval_fun(AVALC)}. -} -\author{ -Stefan Bundfuss -} -\concept{deprecated} -\keyword{deprecated} diff --git a/man/derive_param_bor.Rd b/man/derive_param_bor.Rd index 73f36043..986d665e 100644 --- a/man/derive_param_bor.Rd +++ b/man/derive_param_bor.Rd @@ -119,6 +119,9 @@ The dataframe passed in the \code{dataset} argument with additional columns and/ rows as set in the \code{set_values_to} argument. } \description{ +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#superseded}{\figure{lifecycle-superseded.svg}{options: alt='[Superseded]'}}}{\strong{[Superseded]}} The \code{derive_param_bor()} function has been +superseded in favor of \code{derive_extreme_event()}. + Adds a parameter for best overall response, without confirmation, optionally up to first progressive disease } @@ -270,14 +273,15 @@ derive_param_bor( filter(PARAMCD == "BOR") } \seealso{ -ADRS Functions for adding Parameters: +Other superseded: \code{\link{derive_param_clinbenefit}()}, \code{\link{derive_param_confirmed_bor}()}, \code{\link{derive_param_confirmed_resp}()}, -\code{\link{derive_param_response}()} +\code{\link{derive_param_response}()}, +\code{\link{filter_pd}()} } \author{ Stephen Gormley } -\concept{der_prm_adrs} -\keyword{der_prm_adrs} +\concept{superseded} +\keyword{superseded} diff --git a/man/derive_param_clinbenefit.Rd b/man/derive_param_clinbenefit.Rd index 030a79d1..be7b0884 100644 --- a/man/derive_param_clinbenefit.Rd +++ b/man/derive_param_clinbenefit.Rd @@ -80,6 +80,9 @@ used to uniquely identify subjects.} The input dataset with a new parameter for clinical benefit } \description{ +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#superseded}{\figure{lifecycle-superseded.svg}{options: alt='[Superseded]'}}}{\strong{[Superseded]}} The \code{derive_param_clinbenefit()} function +has been superseded in favor of \code{derive_extreme_event()}. + Adds a parameter for clinical benefit/disease control } \details{ @@ -206,14 +209,15 @@ derive_param_clinbenefit( filter(PARAMCD == "CBR") } \seealso{ -ADRS Functions for adding Parameters: +Other superseded: \code{\link{derive_param_bor}()}, \code{\link{derive_param_confirmed_bor}()}, \code{\link{derive_param_confirmed_resp}()}, -\code{\link{derive_param_response}()} +\code{\link{derive_param_response}()}, +\code{\link{filter_pd}()} } \author{ Andrew Smith } -\concept{der_prm_adrs} -\keyword{der_prm_adrs} +\concept{superseded} +\keyword{superseded} diff --git a/man/derive_param_confirmed_bor.Rd b/man/derive_param_confirmed_bor.Rd index 7c375b8e..b9b6f5b4 100644 --- a/man/derive_param_confirmed_bor.Rd +++ b/man/derive_param_confirmed_bor.Rd @@ -132,6 +132,9 @@ The input dataset with a new parameter for confirmed best overall response } \description{ +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#superseded}{\figure{lifecycle-superseded.svg}{options: alt='[Superseded]'}}}{\strong{[Superseded]}} The \code{derive_param_confirmed_bor()} +function has been superseded in favor of \code{derive_extreme_event()}. + Adds a parameter for confirmed best overall response (BOR) } \details{ @@ -334,14 +337,15 @@ derive_param_confirmed_bor( filter(PARAMCD == "CBOR") } \seealso{ -ADRS Functions for adding Parameters: +Other superseded: \code{\link{derive_param_bor}()}, \code{\link{derive_param_clinbenefit}()}, \code{\link{derive_param_confirmed_resp}()}, -\code{\link{derive_param_response}()} +\code{\link{derive_param_response}()}, +\code{\link{filter_pd}()} } \author{ Stefan Bundfuss } -\concept{der_prm_adrs} -\keyword{der_prm_adrs} +\concept{superseded} +\keyword{superseded} diff --git a/man/derive_param_confirmed_resp.Rd b/man/derive_param_confirmed_resp.Rd index 55ff439a..313b9dfc 100644 --- a/man/derive_param_confirmed_resp.Rd +++ b/man/derive_param_confirmed_resp.Rd @@ -104,6 +104,9 @@ A list of symbols created using \code{exprs()} is expected.} The input dataset with a new parameter for confirmed response } \description{ +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#superseded}{\figure{lifecycle-superseded.svg}{options: alt='[Superseded]'}}}{\strong{[Superseded]}} The \code{derive_param_confirmed_resp()} +function has been superseded in favor of \code{derive_extreme_event()}. + Adds a parameter for confirmed response } \details{ @@ -268,14 +271,15 @@ derive_param_confirmed_resp( filter(PARAMCD == "CRSP") } \seealso{ -ADRS Functions for adding Parameters: +Other superseded: \code{\link{derive_param_bor}()}, \code{\link{derive_param_clinbenefit}()}, \code{\link{derive_param_confirmed_bor}()}, -\code{\link{derive_param_response}()} +\code{\link{derive_param_response}()}, +\code{\link{filter_pd}()} } \author{ Stefan Bundfuss } -\concept{der_prm_adrs} -\keyword{der_prm_adrs} +\concept{superseded} +\keyword{superseded} diff --git a/man/derive_param_response.Rd b/man/derive_param_response.Rd index 3ee56c42..c51e628a 100644 --- a/man/derive_param_response.Rd +++ b/man/derive_param_response.Rd @@ -88,6 +88,9 @@ The input dataset with a new parameter indicating if and when a response occurred } \description{ +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#superseded}{\figure{lifecycle-superseded.svg}{options: alt='[Superseded]'}}}{\strong{[Superseded]}} The \code{derive_param_response()} function has +been superseded in favor of \code{derive_extreme_event()}. + Adds a parameter indicating if a response has been observed. If a response has been observed, \code{AVALC} is set to "Y", \code{AVAL} to 1 and \code{ADT} is set to the @@ -179,14 +182,15 @@ derive_param_response( arrange(USUBJID, PARAMCD, ADT) } \seealso{ -ADRS Functions for adding Parameters: +Other superseded: \code{\link{derive_param_bor}()}, \code{\link{derive_param_clinbenefit}()}, \code{\link{derive_param_confirmed_bor}()}, -\code{\link{derive_param_confirmed_resp}()} +\code{\link{derive_param_confirmed_resp}()}, +\code{\link{filter_pd}()} } \author{ Samia Kabi } -\concept{der_prm_adrs} -\keyword{der_prm_adrs} +\concept{superseded} +\keyword{superseded} diff --git a/man/filter_pd.Rd b/man/filter_pd.Rd index 01584822..3f2e147d 100644 --- a/man/filter_pd.Rd +++ b/man/filter_pd.Rd @@ -38,6 +38,9 @@ A list of symbols created using \code{exprs()} is expected.} A subset of the input dataset } \description{ +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#superseded}{\figure{lifecycle-superseded.svg}{options: alt='[Superseded]'}}}{\strong{[Superseded]}} The \code{filter_pd()} function has been +superseded in favor of \code{filter_relative()}. + Filter a dataset to only include the source parameter records up to and including the first PD (progressive disease). These records are passed to downstream derivations regarding responses such as BOR (best overall @@ -187,8 +190,16 @@ filter_pd( source_datasets = list(adrs = adrs) ) } +\seealso{ +Other superseded: +\code{\link{derive_param_bor}()}, +\code{\link{derive_param_clinbenefit}()}, +\code{\link{derive_param_confirmed_bor}()}, +\code{\link{derive_param_confirmed_resp}()}, +\code{\link{derive_param_response}()} +} \author{ Teckla Akinyi, Stefan Bundfuss } -\concept{utils_fil} -\keyword{utils_fil} +\concept{superseded} +\keyword{superseded} diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R deleted file mode 100644 index 541b84c9..00000000 --- a/tests/testthat/test-utils.R +++ /dev/null @@ -1,53 +0,0 @@ -data <- tibble::tribble( - ~AVALC, - "YES", - "NO" -) - -# call_aval_fun ---- - -## Test 1: AVAL is created ---- -test_that("call_aval_fun Test 1: AVAL is created", { - yn_map <- function(x) { - case_when( - x == "YES" ~ 1, - x == "NO" ~ 0 - ) - } - - expect_warning( - actual <- call_aval_fun( - data, - yn_map - ), - class = "lifecycle_warning_deprecated" - ) - - expect_dfs_equal( - actual, - tibble::tribble( - ~AVALC, ~AVAL, - "YES", 1, - "NO", 0 - ), - keys = c("AVAL") - ) -}) - -## Test 2: Test error for invalid aval_fun ---- -test_that("call_aval_fun Test 2: Test error for invalid aval_fun", { - bad_fun <- function(x) { - abort("Function bad_fun failed!") - } - - expect_error( - suppress_warning( - call_aval_fun( - data, - aval_fun = bad_fun - ), - regexpr = "deprecated" - ), - regexp = "Assigning new AVAL records with aval_fun" - ) -}) diff --git a/vignettes/admiralonco.Rmd b/vignettes/admiralonco.Rmd index 33347b16..4c73029c 100644 --- a/vignettes/admiralonco.Rmd +++ b/vignettes/admiralonco.Rmd @@ -12,50 +12,18 @@ knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) -link <- function(text, url) { - return( - paste0( - "[", text, "]", - "(", url, ")" - ) - ) -} -dyn_link <- function(text, - base_url, - relative_url = "", - # Change to TRUE when admiral adopts multiversion docs - is_multiversion = FALSE, - multiversion_default_ref = "main") { - url <- paste(base_url, relative_url, sep = "/") - if (is_multiversion) { - url <- paste( - base_url, - Sys.getenv("BRANCH_NAME", multiversion_default_ref), - relative_url, - sep = "/" - ) - } - return(link(text, url)) -} -# Other variables -admiral_homepage <- "https://pharmaverse.github.io/admiral/cran-release" ``` # Introduction -As this is a package extension, if you are new to `{admiral}` then the best place to first start -reading would be this `r dyn_link("Get Started", admiral_homepage, "articles/admiral.html")` -guide. This extension package follows the same main idea and conventions, and re-uses many -functions from `{admiral}`, so it is important to thoroughly understand these to be able to -use `{admiralonco}`. +As this is a package extension, if you are new to `{admiral}` then the best +place to first start reading would be the [Get +Started](https://pharmaverse.github.io/admiral/articles/admiral.html) page. This +extension package follows the same main idea and conventions, and re-uses many +functions from `{admiral}`, so it is important to thoroughly understand these to +be able to use `{admiralonco}`. -# Derivations - -The most important functions in `{admiralonco}` are the -[derivations](../reference/index.html#section-derivations). Again these follow the same -conventions as `{admiral}` but are focused to oncology-specific needs. - -# Starting a Script +# Creating Oncology ADaM Datasets For the oncology ADaM data structures, an overview of the flow and example function calls for the most common steps are provided by the following vignettes: @@ -66,7 +34,7 @@ for the most common steps are provided by the following vignettes: - [Creating ADTR](adtr.html) `{admiralonco}` also provides template R scripts as a starting point. They can be -created by calling `use_ad_template()` from {admiral}, e.g., +created by calling `use_ad_template()` from `{admiral}`, e.g., ```{r} library(admiral) @@ -81,7 +49,7 @@ use_ad_template( ``` A list of all available templates can be obtained by `list_all_templates()` -from {admiral}: +from `{admiral}`: ```{r} list_all_templates(package = "admiralonco") diff --git a/vignettes/adrs.Rmd b/vignettes/adrs.Rmd index 2dc5b14d..8f6593a3 100644 --- a/vignettes/adrs.Rmd +++ b/vignettes/adrs.Rmd @@ -14,36 +14,6 @@ knitr::opts_chunk$set( comment = "#>" ) -library(admiral) - -link <- function(text, url) { - return( - paste0( - "[", text, "]", - "(", url, ")" - ) - ) -} -dyn_link <- function(text, - base_url, - relative_url = "", - # Change to TRUE when admiral adopts multiversion docs - is_multiversion = FALSE, - multiversion_default_ref = "main") { - url <- paste(base_url, relative_url, sep = "/") - if (is_multiversion) { - url <- paste( - base_url, - Sys.getenv("BRANCH_NAME", multiversion_default_ref), - relative_url, - sep = "/" - ) - } - return(link(text, url)) -} -# Other variables -admiral_homepage <- "https://pharmaverse.github.io/admiral/cran-release" - library(admiraldev) ``` @@ -95,20 +65,21 @@ read into the environment. This will be a company specific process. Some of the data frames needed may be `ADSL`, `RS` and `TU`. For example purpose, the SDTM and ADaM datasets (based on CDISC Pilot -test data)---which are included in `{pharmaversesdtm}`---are used. +test data)---which are included in `{pharmaversesdtm}` and +`{pharmaverseadam}`---are used. ```{r message=FALSE} library(admiral) library(admiralonco) library(dplyr) library(pharmaversesdtm) +library(pharmaverseadam) library(lubridate) library(stringr) -data("admiral_adsl") +data("adsl") data("rs_onco_recist") data("tu_onco_recist") -adsl <- admiral_adsl rs <- rs_onco_recist tu <- tu_onco_recist @@ -193,7 +164,7 @@ adrs <- adrs %>% PARAM = "Overall Response by Investigator", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1" + PARCAT3 = "RECIST 1.1" ) ``` @@ -259,12 +230,24 @@ those occurring on or after randomization date. If there is more than one assessment at a date, the worst one is flagged. ```{r} +worst_resp <- function(arg) { + case_when( + arg == "NE" ~ 1, + arg == "CR" ~ 2, + arg == "PR" ~ 3, + arg == "SD" ~ 4, + arg == "NON-CR/NON-PD" ~ 5, + arg == "PD" ~ 6, + TRUE ~ 0 + ) +} + adrs <- adrs %>% restrict_derivation( derivation = derive_var_extreme_flag, args = params( by_vars = exprs(STUDYID, USUBJID, ADT), - order = exprs(AVAL, RSSEQ), + order = exprs(worst_resp(AVALC), RSSEQ), new_var = ANL01FL, mode = "last" ), @@ -359,7 +342,7 @@ crsp_y_cr <- event_joined( join_vars = exprs(AVALC, ADT), join_type = "after", order = exprs(ADT), - first_cond = AVALC.join == "CR" & + first_cond_upper = AVALC.join == "CR" & ADT.join >= ADT + days(confirmation_period), condition = AVALC == "CR" & all(AVALC.join %in% c("CR", "NE")) & @@ -377,7 +360,7 @@ crsp_y_pr <- event_joined( join_vars = exprs(AVALC, ADT), join_type = "after", order = exprs(ADT), - first_cond = AVALC.join %in% c("CR", "PR") & + first_cond_upper = AVALC.join %in% c("CR", "PR") & ADT.join >= ADT + days(confirmation_period), condition = AVALC == "PR" & all(AVALC.join %in% c("CR", "PR", "NE")) & @@ -403,7 +386,7 @@ cbor_cr <- event_joined( dataset_name = "ovr", join_vars = exprs(AVALC, ADT), join_type = "after", - first_cond = AVALC.join == "CR" & + first_cond_upper = AVALC.join == "CR" & ADT.join >= ADT + confirmation_period, condition = AVALC == "CR" & all(AVALC.join %in% c("CR", "NE")) & @@ -421,7 +404,7 @@ cbor_pr <- event_joined( dataset_name = "ovr", join_vars = exprs(AVALC, ADT), join_type = "after", - first_cond = AVALC.join %in% c("CR", "PR") & + first_cond_upper = AVALC.join %in% c("CR", "PR") & ADT.join >= ADT + confirmation_period, condition = AVALC == "PR" & all(AVALC.join %in% c("CR", "PR", "NE")) & @@ -478,12 +461,13 @@ adrs <- adrs %>% order = exprs(ADT, RSSEQ), mode = "first", exist_flag = AVALC, + false_value = "N", set_values_to = exprs( PARAMCD = "PD", PARAM = "Disease Progression by Investigator", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = yn_to_numeric(AVALC), ANL01FL = "Y" ) @@ -520,7 +504,8 @@ rsp_y adrs <- adrs %>% derive_extreme_event( by_vars = exprs(STUDYID, USUBJID), - order = exprs(ADT), + order = exprs(event_nr, ADT), + tmp_event_nr_var = event_nr, mode = "first", events = list(rsp_y, no_data_n), source_datasets = list( @@ -532,7 +517,7 @@ adrs <- adrs %>% PARAM = "Response by Investigator (confirmation not required)", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = yn_to_numeric(AVALC), ANL01FL = "Y" ) @@ -569,24 +554,23 @@ list). Thus `ignore_event_order = TRUE` is specified. adrs <- adrs %>% derive_extreme_event( by_vars = exprs(STUDYID, USUBJID), - order = exprs(desc(AVALC), ADT), + order = exprs(desc(AVALC), ADT, event_nr), + tmp_event_nr_var = event_nr, mode = "first", events = list(rsp_y, cb_y, no_data_n), source_datasets = list( ovr = ovr, adsl = adsl ), - ignore_event_order = TRUE, set_values_to = exprs( PARAMCD = "CB", PARAM = "Clinical Benefit by Investigator (confirmation for response not required)", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = yn_to_numeric(AVALC), ANL01FL = "Y" - ), - check_type = "none" + ) ) ``` @@ -615,7 +599,8 @@ response for this subject. adrs <- adrs %>% derive_extreme_event( by_vars = exprs(STUDYID, USUBJID), - order = exprs(ADT), + order = exprs(event_nr, ADT), + tmp_event_nr_var = event_nr, mode = "first", source_datasets = list( ovr = ovr, @@ -627,7 +612,7 @@ adrs <- adrs %>% PARAM = "Best Overall Response by Investigator (confirmation not required)", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = aval_resp(AVALC), ANL01FL = "Y" ) @@ -683,12 +668,13 @@ adrs <- adrs %>% by_vars = exprs(STUDYID, USUBJID), filter_add = PARAMCD == "BOR" & AVALC %in% c("CR", "PR"), exist_flag = AVALC, + false_value = "N", set_values_to = exprs( PARAMCD = "BCP", PARAM = "Best Overall Response of CR/PR by Investigator (confirmation not required)", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = yn_to_numeric(AVALC), ANL01FL = "Y" ) @@ -741,20 +727,20 @@ is specified. adrs <- adrs %>% derive_extreme_event( by_vars = exprs(STUDYID, USUBJID), - order = exprs(desc(AVALC), ADT), + order = exprs(desc(AVALC), ADT, event_nr), + tmp_event_nr_var = event_nr, mode = "first", source_datasets = list( ovr = ovr, adsl = adsl ), events = list(crsp_y_cr, crsp_y_pr, no_data_n), - ignore_event_order = TRUE, set_values_to = exprs( PARAMCD = "CRSP", PARAM = "Confirmed Response by Investigator", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = yn_to_numeric(AVALC), ANL01FL = "Y" ) @@ -763,30 +749,30 @@ adrs <- adrs %>% adrs <- adrs %>% derive_extreme_event( by_vars = exprs(STUDYID, USUBJID), - order = exprs(desc(AVALC), ADT), + order = exprs(desc(AVALC), ADT, event_nr), + tmp_event_nr_var = event_nr, mode = "first", events = list(crsp_y_cr, crsp_y_pr, cb_y, no_data_n), source_datasets = list( ovr = ovr, adsl = adsl ), - ignore_event_order = TRUE, set_values_to = exprs( PARAMCD = "CCB", PARAM = "Confirmed Clinical Benefit by Investigator", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = yn_to_numeric(AVALC), ANL01FL = "Y" - ), - check_type = "none" + ) ) adrs <- adrs %>% derive_extreme_event( by_vars = exprs(STUDYID, USUBJID), - order = exprs(ADT), + order = exprs(event_nr, ADT), + tmp_event_nr_var = event_nr, mode = "first", events = list(cbor_cr, cbor_pr, bor_sd, bor_non_crpd, bor_pd, bor_ne, no_data_missing), source_datasets = list( @@ -798,7 +784,7 @@ adrs <- adrs %>% PARAM = "Best Confirmed Overall Response by Investigator", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = aval_resp(AVALC), ANL01FL = "Y" ) @@ -809,12 +795,13 @@ adrs <- adrs %>% by_vars = exprs(STUDYID, USUBJID), filter_add = PARAMCD == "CBOR" & AVALC %in% c("CR", "PR"), exist_flag = AVALC, + false_value = "N", set_values_to = exprs( PARAMCD = "CBCP", PARAM = "Best Confirmed Overall Response of CR/PR by Investigator", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = yn_to_numeric(AVALC), ANL01FL = "Y" ) @@ -854,24 +841,23 @@ cb_y_pd <- event( adrs <- adrs %>% derive_extreme_event( by_vars = exprs(STUDYID, USUBJID), - order = exprs(desc(AVALC), ADT), + order = exprs(desc(AVALC), ADT, event_nr), + tmp_event_nr_var = event_nr, mode = "first", events = list(crsp_y_cr, crsp_y_pr, cb_y, cb_y_pd, no_data_n), source_datasets = list( ovr = ovr, adsl = adsl ), - ignore_event_order = TRUE, set_values_to = exprs( PARAMCD = "ACCB", PARAM = "Alternative Confirmed Clinical Benefit by Investigator", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = yn_to_numeric(AVALC), ANL01FL = "Y" - ), - check_type = "none" + ) ) ``` @@ -896,7 +882,8 @@ bor_ned <- event( adrs <- adrs %>% derive_extreme_event( by_vars = exprs(STUDYID, USUBJID), - order = exprs(ADT), + order = exprs(event_nr, ADT), + tmp_event_nr_var = event_nr, mode = "first", source_datasets = list( ovr = ovr, @@ -907,11 +894,11 @@ adrs <- adrs %>% PARAMCD = "A1BOR", PARAM = paste( "Best Overall Response by Investigator (confirmation not required)", - "- Recist 1.1 adjusted for NED at Baseline" + "- RECIST 1.1 adjusted for NED at Baseline" ), PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1 adjusted for NED at Baseline", + PARCAT3 = "RECIST 1.1 adjusted for NED at Baseline", AVAL = aval_resp(AVALC), ANL01FL = "Y" ) @@ -937,7 +924,7 @@ adrs_bicr <- rs %>% PARAM = "Overall Response by BICR", PARCAT1 = "Tumor Response", PARCAT2 = "Blinded Independent Central Review", - PARCAT3 = "Recist 1.1" + PARCAT3 = "RECIST 1.1" ) ``` @@ -970,6 +957,7 @@ adrs <- adrs %>% by_vars = exprs(STUDYID, USUBJID), filter_add = !is.na(DTHDT), exist_flag = AVALC, + false_value = "N", set_values_to = exprs( PARAMCD = "DEATH", PARAM = "Death", @@ -1009,7 +997,7 @@ adrs <- adrs %>% PARAM = "Last Disease Assessment by Investigator", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", ANL01FL = "Y" ) ) @@ -1047,7 +1035,7 @@ adrs <- adrs %>% PARAMCD = "MDIS", PARAM = "Measurable Disease at Baseline by Investigator", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = yn_to_numeric(AVALC), ANL01FL = "Y" ) @@ -1109,4 +1097,4 @@ dataset_vignette( ADaM | Sample Code ---- | -------------- -ADRS | `r dyn_link("ad_adrs.R", "https://github.com/pharmaverse/admiralonco/blob", "inst/templates/ad_adrs.R", is_multiversion = TRUE)` +ADRS | `admiral::use_ad_template("ADRS", package = "admiralonco")` diff --git a/vignettes/adrs_basic.Rmd b/vignettes/adrs_basic.Rmd index 973ceba2..3df21b59 100644 --- a/vignettes/adrs_basic.Rmd +++ b/vignettes/adrs_basic.Rmd @@ -14,36 +14,6 @@ knitr::opts_chunk$set( comment = "#>" ) -library(admiral) - -link <- function(text, url) { - return( - paste0( - "[", text, "]", - "(", url, ")" - ) - ) -} -dyn_link <- function(text, - base_url, - relative_url = "", - # Change to TRUE when admiral adopts multiversion docs - is_multiversion = FALSE, - multiversion_default_ref = "main") { - url <- paste(base_url, relative_url, sep = "/") - if (is_multiversion) { - url <- paste( - base_url, - Sys.getenv("BRANCH_NAME", multiversion_default_ref), - relative_url, - sep = "/" - ) - } - return(link(text, url)) -} -# Other variables -admiral_homepage <- "https://pharmaverse.github.io/admiral/cran-release" - library(admiraldev) ``` @@ -93,21 +63,22 @@ To start, all data frames needed for the creation of `ADRS` should be read into the environment. This will be a company specific process. Some of the data frames needed may be `ADSL`, `RS` and `TU`. -For example purpose, the SDTM and ADaM datasets (based on CDISC Pilot -test data)---which are included in `{pharmaversesdtm}`---are used. +For example purpose, the SDTM and ADaM datasets (based on CDISC Pilot test +data)---which are included in `{pharmaversesdtm}` and `{pharmaverseadam}`---are +used. ```{r message=FALSE} library(admiral) library(admiralonco) library(dplyr) library(pharmaversesdtm) +library(pharmaverseadam) library(lubridate) library(stringr) -data("admiral_adsl") +data("adsl") data("rs_onco_recist") data("tu_onco_recist") -adsl <- admiral_adsl rs <- rs_onco_recist tu <- tu_onco_recist @@ -192,7 +163,7 @@ adrs <- adrs %>% PARAM = "Overall Response by Investigator", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1" + PARCAT3 = "RECIST 1.1" ) ``` @@ -258,12 +229,24 @@ those occurring on or after randomization date. If there is more than one assessment at a date, the worst one is flagged. ```{r} +worst_resp <- function(arg) { + case_when( + arg == "NE" ~ 1, + arg == "CR" ~ 2, + arg == "PR" ~ 3, + arg == "SD" ~ 4, + arg == "NON-CR/NON-PD" ~ 5, + arg == "PD" ~ 6, + TRUE ~ 0 + ) +} + adrs <- adrs %>% restrict_derivation( derivation = derive_var_extreme_flag, args = params( by_vars = exprs(STUDYID, USUBJID, ADT), - order = exprs(AVAL, RSSEQ), + order = exprs(worst_resp(AVALC), RSSEQ), new_var = ANL01FL, mode = "last" ), @@ -344,12 +327,13 @@ adrs <- adrs %>% order = exprs(ADT, RSSEQ), mode = "first", exist_flag = AVALC, + false_value = "N", set_values_to = exprs( PARAMCD = "PD", PARAM = "Disease Progression by Investigator", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = yn_to_numeric(AVALC), ANL01FL = "Y" ) @@ -414,7 +398,7 @@ adrs <- adrs %>% PARAM = "Response by Investigator (confirmation not required)", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = yn_to_numeric(AVALC), ANL01FL = "Y" ) @@ -464,7 +448,7 @@ adrs <- adrs %>% PARAM = "Clinical Benefit by Investigator (confirmation for response not required)", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = yn_to_numeric(AVALC), ANL01FL = "Y" ) @@ -501,7 +485,7 @@ adrs <- adrs %>% PARAM = "Best Overall Response by Investigator (confirmation not required)", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = aval_resp(AVALC), ANL01FL = "Y" ) @@ -558,12 +542,13 @@ adrs <- adrs %>% order = exprs(ADT, RSSEQ), mode = "first", exist_flag = AVALC, + false_value = "N", set_values_to = exprs( PARAMCD = "BCP", PARAM = "Best Overall Response of CR/PR by Investigator (confirmation not required)", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = yn_to_numeric(AVALC), ANL01FL = "Y" ) @@ -602,7 +587,7 @@ adrs <- adrs %>% PARAM = "Confirmed Response by Investigator", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = yn_to_numeric(AVALC), ANL01FL = "Y" ) @@ -628,7 +613,7 @@ adrs <- adrs %>% PARAM = "Confirmed Clinical Benefit by Investigator", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = yn_to_numeric(AVALC), ANL01FL = "Y" ) @@ -646,7 +631,7 @@ adrs <- adrs %>% PARAM = "Best Confirmed Overall Response by Investigator", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = aval_resp(AVALC), ANL01FL = "Y" ) @@ -659,12 +644,13 @@ adrs <- adrs %>% order = exprs(ADT, RSSEQ), mode = "first", exist_flag = AVALC, + false_value = "N", set_values_to = exprs( PARAMCD = "CBCP", PARAM = "Best Confirmed Overall Response of CR/PR by Investigator", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = yn_to_numeric(AVALC), ANL01FL = "Y" ) @@ -700,7 +686,7 @@ adrs_bicr <- rs %>% PARAM = "Overall Response by BICR", PARCAT1 = "Tumor Response", PARCAT2 = "Blinded Independent Central Review", - PARCAT3 = "Recist 1.1" + PARCAT3 = "RECIST 1.1" ) ``` @@ -733,6 +719,7 @@ adrs <- adrs %>% by_vars = exprs(STUDYID, USUBJID), filter_add = !is.na(DTHDT), exist_flag = AVALC, + false_value = "N", set_values_to = exprs( PARAMCD = "DEATH", PARAM = "Death", @@ -772,7 +759,7 @@ adrs <- adrs %>% PARAM = "Last Disease Assessment by Investigator", PARCAT1 = "Tumor Response", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", ANL01FL = "Y" ) ) @@ -810,7 +797,7 @@ adrs <- adrs %>% PARAMCD = "MDIS", PARAM = "Measurable Disease at Baseline by Investigator", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = yn_to_numeric(AVALC), ANL01FL = "Y" ) @@ -872,4 +859,4 @@ dataset_vignette( ADaM | Sample Code ---- | -------------- -ADRS_BASIC | `r dyn_link("ad_adrs_basic.R", "https://github.com/pharmaverse/admiralonco/blob", "inst/templates/ad_adrs_basic.R", is_multiversion = TRUE)` +ADRS_BASIC | `admiral::use_ad_template("ADRS_BASIC", package = "admiralonco")` diff --git a/vignettes/adtr.Rmd b/vignettes/adtr.Rmd index b8855ba7..5bb8c01c 100644 --- a/vignettes/adtr.Rmd +++ b/vignettes/adtr.Rmd @@ -13,34 +13,6 @@ knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) -library(admiral) -link <- function(text, url) { - return( - paste0( - "[", text, "]", - "(", url, ")" - ) - ) -} -dyn_link <- function(text, - base_url, - relative_url = "", - # Change to TRUE when admiral adopts multiversion docs - is_multiversion = FALSE, - multiversion_default_ref = "main") { - url <- paste(base_url, relative_url, sep = "/") - if (is_multiversion) { - url <- paste( - base_url, - Sys.getenv("BRANCH_NAME", multiversion_default_ref), - relative_url, - sep = "/" - ) - } - return(link(text, url)) -} -# Other variables -admiral_homepage <- "https://pharmaverse.github.io/admiral" library(admiraldev) ``` @@ -78,6 +50,7 @@ The examples of this vignette require the following packages. library(admiral) library(dplyr) library(pharmaversesdtm) +library(pharmaverseadam) library(lubridate) library(stringr) library(admiralonco) @@ -104,9 +77,9 @@ To start, all data frames needed for the creation of `ADTR` should be read into Some of the data frames needed may be `ADSL`, `ADRS` ,`RS`, `TU`, `TR`, `SUPPTU` `SUPPTR`. For example purposes, the SDTM and ADaM datasets (based on CDISC Pilot test -data)---which are included in `{pharmaversesdtm}`---are used. Also, see -[Handling of Missing -Values](https://pharmaverse.github.io/admiral/cran-release/articles/admiral.html#handling-of-missing-values) +data)---which are included in `{pharmaversesdtm}` and `{pharmaverseadam}`---are +used. Also, see [Handling of Missing +Values](https://pharmaverse.github.io/admiral/articles/admiral.html#handling-of-missing-values) explains why we need to use the `convert_blanks_to_na()` function. On the `TR` domain we filter on where tumor assessment short name `TRTESTCD` is @@ -116,13 +89,12 @@ then the template code where we derive parameters for lesions diameters should be updated accordingly. ```{r} -data("admiral_adsl") -data("admiral_adrs") +data("adsl") +data("adrs_onco") data("rs_onco_recist") data("tu_onco_recist") data("tr_onco_recist") -adsl <- admiral_adsl -adrs <- admiral_adrs +adrs <- adrs_onco tu <- tu_onco_recist tr <- tr_onco_recist rs <- rs_onco_recist @@ -272,7 +244,7 @@ adtr <- bind_rows( mutate( PARCAT1 = "Target Lesion(s)", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1", + PARCAT3 = "RECIST 1.1", AVAL = TRSTRESN, ANL01FL = if_else(!is.na(AVAL), "Y", NA_character_) ) %>% @@ -302,21 +274,24 @@ flags therefore should be setup according to your company specifications. In the example below, the lesion sizes are counted and grouped according to the by variables specified, in this case we group by the visit (`AVISIT` and `AVISITN`) to ensure that the correct lesion measurements are summed together. +If there are different analysis day/dates (`ADY`/`ADT`) associated with a +particular visit, we take the minimum day/date. ```{r} -adtr_sum <- get_summary_records( - adtr, +adtr_sum <- derive_summary_records( + dataset_add = adtr, by_vars = exprs(STUDYID, USUBJID, !!!adsl_vars, AVISIT, AVISITN), - filter = (str_starts(PARAMCD, "LDIAM") & TULOCGR1 == "NON-NODAL") | + filter_add = (str_starts(PARAMCD, "LDIAM") & TULOCGR1 == "NON-NODAL") | (str_starts(PARAMCD, "NLDIAM") & TULOCGR1 == "NODAL"), - analysis_var = AVAL, - summary_fun = function(x) sum(x, na.rm = TRUE), set_values_to = exprs( + AVAL = sum(AVAL, na.rm = TRUE), + ADY = min(ADY, na.rm = TRUE), + ADT = min(ADT, na.rm = TRUE), PARAMCD = "SDIAM", PARAM = "Target Lesions Sum of Diameters by Investigator", PARCAT1 = "Target Lesion(s)", PARCAT2 = "Investigator", - PARCAT3 = "Recist 1.1" + PARCAT3 = "RECIST 1.1" ) ) ``` @@ -325,10 +300,10 @@ adtr_sum <- get_summary_records( dataset_vignette( adtr_sum %>% arrange(USUBJID, AVISITN) %>% - select(USUBJID, PARAMCD, PARAM, AVISIT, AVAL, everything()), - display_vars = exprs(USUBJID, PARAMCD, PARAM, AVISIT, AVAL) + select(USUBJID, PARAMCD, PARAM, AVISIT, AVAL, ADT, ADY, everything()), + display_vars = exprs(USUBJID, PARAMCD, PARAM, AVISIT, AVAL, ADT, ADY) ) -``` +``` The analysis flag `ANL01FL` flags the sum of diameters where the number of lesions assessed at baseline and at post-baseline match. To assess whether the number of lesions expected and assessed match, you could compare lesion identifiers (`TR.TRLNKID`) or use the previous variables set up earlier to compare lesion expected (`LSEXP`) vs lesion assessed (`LSASS`) or check for target lesion response (from `RS`) = `NE`. A target lesion response of `NE` means all lesions from baseline are not measured at that post-baseline visit. @@ -354,58 +329,20 @@ adtr_sum <- adtr_sum %>% filter_add = AVISIT == "BASELINE" & ((str_starts(PARAMCD, "LDIAM") & TULOCGR1 == "NON-NODAL") | (str_starts(PARAMCD, "NLDIAM") & TULOCGR1 == "NODAL")), - new_var = LSEXP, - analysis_var = TRLNKID, - summary_fun = function(x) paste(sort(x), collapse = ", ") + new_vars = exprs(LSEXP = paste(sort(TRLNKID), collapse = ", ")) ) %>% derive_var_merged_summary( dataset_add = adtr, by_vars = exprs(USUBJID, AVISIT), filter_add = ((str_starts(PARAMCD, "LDIAM") & TULOCGR1 == "NON-NODAL") | (str_starts(PARAMCD, "NLDIAM") & TULOCGR1 == "NODAL")) & ANL01FL == "Y", - new_var = LSASS, - analysis_var = TRLNKID, - summary_fun = function(x) paste(sort(x), collapse = ", ") + new_vars = exprs(LSASS = paste(sort(TRLNKID), collapse = ", ")) ) %>% mutate( ANL01FL = if_else(LSEXP == LSASS, "Y", NA_character_) ) ``` -In the next step we include the analysis day and date (`ADY`/`ADT`) variables to -the sum of diameter parameter dataset. If there are different analysis -day/dates associated with a particular visit, we take the minimum day/date. - -```{r} -adtr_sum <- adtr_sum %>% - derive_var_merged_summary( - dataset_add = adtr, - by_vars = exprs(USUBJID, AVISIT), - filter_add = (str_starts(PARAMCD, "LDIAM") & TULOCGR1 == "NON-NODAL") | - (str_starts(PARAMCD, "NLDIAM") & TULOCGR1 == "NODAL"), - new_var = ADY, - analysis_var = ADY, - summary_fun = function(x) min(x, na.rm = TRUE) - ) %>% - derive_var_merged_summary( - dataset_add = adtr, - by_vars = exprs(USUBJID, AVISIT), - filter_add = (str_starts(PARAMCD, "LDIAM") & TULOCGR1 == "NON-NODAL") | - (str_starts(PARAMCD, "NLDIAM") & TULOCGR1 == "NODAL"), - new_var = ADT, - analysis_var = ADT, - summary_fun = function(x) min(x, na.rm = TRUE) - ) -``` - -```{r, echo=FALSE} -dataset_vignette( - arrange(adtr_sum, USUBJID, AVISITN), - display_vars = exprs(USUBJID, PARAMCD, AVISIT, LSEXP, LSASS, ANL01FL, ADT, ADY) -) -``` - - ## Derive Baseline (`ABLFL`, `BASE`) {#base} These functions are available in `admiral`, below examples show its usage for @@ -746,8 +683,4 @@ dataset_vignette( ADaM | Sample Code ---- | -------------- -`ADTR` | `r dyn_link("ad_adtr.R", "https://github.com/pharmaverse/admiralonco/blob", "inst/templates/ad_adtr.R", is_multiversion = TRUE)` - - - - +`ADTR` | `admiral::use_ad_template("ADTR", package = "admiralonco")` diff --git a/vignettes/adtte.Rmd b/vignettes/adtte.Rmd index 34c26d54..cd481bdf 100644 --- a/vignettes/adtte.Rmd +++ b/vignettes/adtte.Rmd @@ -13,34 +13,6 @@ knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) -link <- function(text, url) { - return( - paste0( - "[", text, "]", - "(", url, ")" - ) - ) -} -dyn_link <- function(text, - base_url, - relative_url = "", - # Change to TRUE when admiral adopts multiversion docs - is_multiversion = FALSE, - multiversion_default_ref = "main") { - url <- paste(base_url, relative_url, sep = "/") - if (is_multiversion) { - url <- paste( - base_url, - Sys.getenv("BRANCH_NAME", multiversion_default_ref), - relative_url, - sep = "/" - ) - } - return(link(text, url)) -} -# Other variables -admiral_homepage <- "https://pharmaverse.github.io/admiral/cran-release" - library(admiraldev) ``` @@ -70,6 +42,7 @@ The examples of this vignette require the following packages. ```{r, warning=FALSE, message=FALSE} library(admiral) library(admiralonco) +library(pharmaverseadam) library(dplyr) library(lubridate) ``` @@ -87,15 +60,14 @@ library(lubridate) To start, all datasets needed for the creation of the time-to-event dataset should be read into the environment. This will be a company specific process. -For example purpose, the ADaM datasets---which are included -in `{admiral}` and `{admiralonco}`---are used. An alternative might be to use -`ADEVENT` as input. +For example purpose, the ADaM datasets---which are included in +`{pharmaverseadam}`---are used. An alternative might be to use `ADEVENT` as +input. ```{r} -data("admiral_adsl") -data("admiral_adrs") -adsl <- admiral_adsl -adrs <- admiral_adrs +data("adsl") +data("adrs_onco") +adrs <- adrs_onco ``` ## Derive Parameters (`CNSR`, `ADT`, `STARTDT`) {#parameters} @@ -219,7 +191,7 @@ dataset_vignette( ### Creating Your Own Time-to-Event Source Objects {#tteobj} We advise you consult the `{admiral}` -`r dyn_link("Creating a BDS Time-to-Event ADaM vignette", admiral_homepage, "articles/bds_tte.html")` +[Creating a BDS Time-to-Event ADaM vignette](https://pharmaverse.github.io/admiral/articles/bds_tte.html) for further guidance on the different options available and more examples. One extra common oncology case we include here is around PFS when censoring @@ -375,4 +347,4 @@ dataset_vignette( ADaM | Sample Code ---- | -------------- -ADTTE | `r dyn_link("ad_adtte.R", "https://github.com/pharmaverse/admiralonco/blob", "inst/templates/ad_adtte.R", is_multiversion = TRUE)` +ADTTE | `admiral::use_ad_template("ADTTE", package = "admiralonco")` diff --git a/vignettes/articles/website-versions.Rmd b/vignettes/articles/website-versions.Rmd new file mode 100644 index 00000000..5143f6d2 --- /dev/null +++ b/vignettes/articles/website-versions.Rmd @@ -0,0 +1,82 @@ +--- +title: "Previous Versions of Website" +--- + +```{r, include = FALSE} +# TO USE THIS ARTICLE, THE DESCRIPTION FILE MUST INCLUDE +# Config/Needs/website: gert +# Make sure to copy the gh-pages branch to your local git + +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + +```{r setup, include=FALSE} +base_url <- + "https://pharmaverse.github.io/admiralonco/" # include the trailing backslash! + +# get list of all files in the `gh-pages` branch +df_all_files <- tryCatch(gert::git_ls(ref = "gh-pages"), error = function(x) FALSE) + +# if a local user (not on CI) does not have a copy of the `gh-pages` branch, exit silently +if (!isTRUE(as.logical(Sys.getenv("CI"))) && isFALSE(df_all_files)) { + knitr::knit_exit() +} +``` + +```{r include=FALSE} +# extract all folders in the root of the branch +all_folders <- + sub("/.*", "", df_all_files$path)[grepl( + x = df_all_files$path, + pattern = "/", + fixed = TRUE + )] |> + unique() + +# subset to all version folders +all_version_folders <- + all_folders[grep("^v[0-9]+|dev", x = all_folders)] |> + rev() +# more dev first if it appears +if ("dev" %in% all_version_folders) { + all_version_folders <- c("dev", all_version_folders) |> unique() +} + +# release dates of prior tags +df_tags <- gert::git_tag_list() +df_tags <- df_tags[df_tags$name %in% all_version_folders, ] +df_tags$date <- + lapply( + df_tags$commit, + FUN = function(x) { + tryCatch( + gert::git_commit_info(ref = x)$time |> as.Date() |> as.character(), + error = function(x) NA + ) + } + ) |> + unlist() +df_tags <- df_tags[!is.na(df_tags$date), ] + +lst_tag_dates <- + paste0(" (", df_tags$date, ")") |> + as.list() |> + setNames(df_tags$name) + +# string with all markdown links +str_website_links <- + lapply( + X = all_version_folders, + FUN = function(x) { + x_label <- ifelse(x %in% "dev", "Development Site", x) + paste0("[", x_label, lst_tag_dates[[x]], "](", paste0(base_url, x), ")") + } + ) |> + unlist() |> + paste(collapse = "\n\n") +``` + +`r str_website_links` diff --git a/vignettes/nactdt.Rmd b/vignettes/nactdt.Rmd index 94c5decf..6c5b0f46 100644 --- a/vignettes/nactdt.Rmd +++ b/vignettes/nactdt.Rmd @@ -13,35 +13,6 @@ knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) -library(admiralonco) -link <- function(text, url) { - return( - paste0( - "[", text, "]", - "(", url, ")" - ) - ) -} -dyn_link <- function(text, - base_url, - relative_url = "", - # Change to TRUE when admiral adopts multiversion docs - is_multiversion = FALSE, - multiversion_default_ref = "main") { - url <- paste(base_url, relative_url, sep = "/") - if (is_multiversion) { - url <- paste( - base_url, - Sys.getenv("BRANCH_NAME", multiversion_default_ref), - relative_url, - sep = "/" - ) - } - return(link(text, url)) -} -# Other variables -admiral_homepage <- "https://pharmaverse.github.io/admiral/cran-release" - library(admiraldev) ``` @@ -72,7 +43,9 @@ library(admiral) library(pharmaverseadam) library(dplyr) +data("adsl") adsl_onco <- adsl +data("adrs_onco") cm <- tribble( ~STUDYID, ~USUBJID, ~CMCAT, ~CMSCAT, ~CMTRT, ~CMSTDTC, @@ -121,24 +94,29 @@ dataset_vignette( ## Multiple Sources - Prerequisite Steps {#multiinput} -To derive the New Anti-Cancer Therapy start date with data from multiple sources, the function `admiral::derive_var_extreme_dt()` can be used, or if time part is needed, `admiral::derive_var_extreme_dtm()` can be used. - +To derive the New Anti-Cancer Therapy start date with data from multiple +sources, the function `admiral::derive_vars_extreme_event()` can be used. ### Prerequisite -Prior to calling the function, an input `date_source` object must be created for each source dataset using `admiral::date_source()`. Within this function, any company-specific subsetting can be passed to the `filter` argument. If numeric version of the dates will be needed, `admiral::convert_dtc_to_dt()`, or if time part is needed, `admiral::convert_dtc_to_dtm()` can be used as part of an expression for the `new_vars` argument. +Prior to calling the function, an input `event` object must be created for each +source dataset using `admiral::event()`. Within this function, any +company-specific subsetting can be passed to the `condition` argument. If +numeric version of the dates will be needed, `admiral::convert_dtc_to_dt()`, or +if time part is needed, `admiral::convert_dtc_to_dtm()` can be used as part of +an expression for the `set_values_to` argument. ```{r message=FALSE} -cm_date <- date_source( +cm_date <- event( dataset_name = "cm", - filter = CMSCAT == "CHEMOTHERAPY" & CMCAT == "ON TREATMENT" & !is.na(CMSTDTC), - date = convert_dtc_to_dt(CMSTDTC) + condition = CMSCAT == "CHEMOTHERAPY" & CMCAT == "ON TREATMENT" & !is.na(CMSTDTC), + set_values_to = exprs(NACTDT = convert_dtc_to_dt(CMSTDTC)) ) -pr_date <- date_source( +pr_date <- event( dataset_name = "pr", - filter = PRCAT == "CANCER RELATED" & PRSCAT == "ON TREATMENT" & !is.na(PRSTDTC), - date = convert_dtc_to_dt(PRSTDTC) + condition = PRCAT == "CANCER RELATED" & PRSCAT == "ON TREATMENT" & !is.na(PRSTDTC), + set_values_to = exprs(NACTDT = convert_dtc_to_dt(PRSTDTC)) ) ``` @@ -148,9 +126,11 @@ After completion of the prerequisite step, the new anti-cancer date can be deriv ```{r message=FALSE} adsl <- adsl_onco %>% - derive_var_extreme_dt( - new_var = NACTDT, - cm_date, pr_date, + derive_vars_extreme_event( + by_vars = exprs(STUDYID, USUBJID), + order = exprs(NACTDT), + new_vars = exprs(NACTDT), + events = list(cm_date, pr_date), source_datasets = list( cm = cm, pr = pr @@ -173,28 +153,32 @@ Please refer to `{admiralonco}` [Derive `ANL01FL`](adrs.html#anl01fl) for an exa ## Derive Date Parameter {#par} -As of `{admiral}` version 0.11.0, `admiral::derive_param_extreme_record()` is recommended to be used for deriving parameter based on the first or last observation from single and multiple sources. +The `{admiral}` function `admiral::derive_extreme_event()` can be used for +deriving parameter based on the first or last observation from single and +multiple sources. -Based on individual company standards, this parameter may be added to an event or date dataset such as `ADEVENT` or `ADDATES`, which are generally intermediate datasets to `ADTTE`. For demonstration purpose, a new anti-cancer date parameter will be merged into `ADRS`. A list of `record_source()` objects is expected and this will contain the sources of the dates and any company specific filtering. +Based on individual company standards, this parameter may be added to an event +or date dataset such as `ADEVENT` or `ADDATES`, which are generally intermediate +datasets to `ADTTE`. For demonstration purpose, a new anti-cancer date parameter +will be merged into `ADRS`. A list of `event()` objects is expected and this +will contain the sources of the dates and any company specific filtering. ```{r, eval=TRUE, echo=TRUE} -library(admiralonco) - -adrs <- derive_param_extreme_record( +adrs <- derive_extreme_event( dataset = adrs_onco, - sources = list( - records_source( + events = list( + event( dataset_name = "cm", - filter = CMSCAT == "CHEMOTHERAPY" & CMCAT == "ON TREATMENT" & !is.na(CMSTDTC), - new_vars = exprs( + condition = CMSCAT == "CHEMOTHERAPY" & CMCAT == "ON TREATMENT" & !is.na(CMSTDTC), + set_values_to = exprs( ADT = convert_dtc_to_dt(CMSTDTC), AVALC = CMTRT ) ), - records_source( + event( dataset_name = "pr", - filter = PRCAT == "CANCER RELATED" & PRSCAT == "ON TREATMENT" & !is.na(PRSTDTC), - new_vars = exprs( + condition = PRCAT == "CANCER RELATED" & PRSCAT == "ON TREATMENT" & !is.na(PRSTDTC), + set_values_to = exprs( ADT = convert_dtc_to_dt(PRSTDTC), AVALC = PRTRT )