diff --git a/adam/adpc.R b/adam/adpc.R index 4adf128a..f285f844 100644 --- a/adam/adpc.R +++ b/adam/adpc.R @@ -56,8 +56,14 @@ pc_dates <- pc %>% # Derive event ID and nominal relative time from first dose (NFRLT) mutate( EVID = 0, - DRUG = PCTEST, - NFRLT = if_else(PCTPTNUM < 0, 0, PCTPTNUM), .after = USUBJID + DRUG = PCTEST + ) %>% + derive_var_nfrlt( + new_var = NFRLT, + new_var_unit = FRLTU, + out_unit = "HOURS", + tpt_var = PCTPT, + visit_day = VISITDY ) ## ----r------------------------------------------------------------------------ @@ -85,11 +91,13 @@ ex_dates <- ex %>% ) %>% # Derive event ID and nominal relative time from first dose (NFRLT) mutate( - EVID = 1, - NFRLT = case_when( - VISITDY == 1 ~ 0, - TRUE ~ 24 * VISITDY - ) + EVID = 1 + ) %>% + derive_var_nfrlt( + new_var = NFRLT, + new_var_unit = FRLTU, + out_unit = "HOURS", + visit_day = VISITDY ) %>% # Set missing end dates to start date mutate(AENDTM = case_when( @@ -233,16 +241,17 @@ adpc_arrlt <- bind_rows(adpc_nom_next, ex_exp) %>% new_var = AFRLT, start_date = FANLDTM, end_date = ADTM, - out_unit = "hours", + out_unit = "HOURS", floor_in = FALSE, add_one = FALSE ) %>% # Derive Actual Relative Time from Reference Dose (ARRLT) derive_vars_duration( new_var = ARRLT, + new_var_unit = RRLTU, start_date = ADTM_prev, end_date = ADTM, - out_unit = "hours", + out_unit = "HOURS", floor_in = FALSE, add_one = FALSE ) %>% @@ -251,7 +260,7 @@ adpc_arrlt <- bind_rows(adpc_nom_next, ex_exp) %>% new_var = AXRLT, start_date = ADTM_next, end_date = ADTM, - out_unit = "hours", + out_unit = "HOURS", floor_in = FALSE, add_one = FALSE ) %>% @@ -330,8 +339,6 @@ adpc_aval <- adpc_nrrlt %>% ) %>% # Derive relative time units mutate( - FRLTU = "h", - RRLTU = "h", # Derive PARAMCD PARAMCD = coalesce(PCTESTCD, "DOSE"), ALLOQ = PCLLOQ, diff --git a/adam/adpc.qmd b/adam/adpc.qmd index 7a06c8f1..bb4fb247 100644 --- a/adam/adpc.qmd +++ b/adam/adpc.qmd @@ -16,7 +16,7 @@ The Non-compartmental analysis (NCA) ADaM uses the CDISC Implementation Guide (< ## First Load Packages -First we will load the packages required for our project. We will use `{admiral}` for the creation of analysis data. `{admiral}` requires `{dplyr}`, `{lubridate}` and `{stringr}`. Find other `{admiral}` functions and related variables by searching [admiraldiscovery](). We will use `{metacore}` and `{metatools}` to store and manipulate metadata from our specifications. We will use `{xportr}` to perform checks on the final data and export to a transport file. +First we will load the packages required for our project. We will use `{admiral}` for the creation of analysis data. `{admiral}` requires `{dplyr}`, `{lubridate}` and `{stringr}`. Find other `{admiral}` functions and related variables by searching [admiraldiscovery](https://pharmaverse.github.io/admiraldiscovery/articles/reactable.html). We will use `{metacore}` and `{metatools}` to store and manipulate metadata from our specifications. We will use `{xportr}` to perform checks on the final data and export to a transport file. The source SDTM data will come from the CDISC pilot study data stored in `{pharmaversesdtm}`. @@ -71,7 +71,7 @@ vs <- convert_blanks_to_na(vs) ### Derive PC Dates -Here we use `{admiral}` functions for working with dates and we will also create a nominal time from first dose `NFRLT` for `PC` data based on `PCTPTNUM`. +Here we use `{admiral}` functions for working with dates and we will also create a nominal time from first dose `NFRLT` for `PC` data using `derive_var_nfrlt()`. ```{r} #| label: PC Dates @@ -101,8 +101,14 @@ pc_dates <- pc %>% # Derive event ID and nominal relative time from first dose (NFRLT) mutate( EVID = 0, - DRUG = PCTEST, - NFRLT = if_else(PCTPTNUM < 0, 0, PCTPTNUM), .after = USUBJID + DRUG = PCTEST + ) %>% + derive_var_nfrlt( + new_var = NFRLT, + new_var_unit = FRLTU, + out_unit = "HOURS", + tpt_var = PCTPT, + visit_day = VISITDY ) ``` @@ -112,7 +118,7 @@ print_df(pc_dates %>% select(USUBJID, PCTEST, ADTM, VISIT, PCTPT, NFRLT)) ### Get Dosing Information -Here we also create nominal time from first dose `NFRLT` for `EX` data based on `VISITDY`. +Here we also create nominal time from first dose `NFRLT` for `EX` data based on `VISITDY` using `derive_var_nfrlt()`. ```{r} #| label: Dosing @@ -141,11 +147,13 @@ ex_dates <- ex %>% ) %>% # Derive event ID and nominal relative time from first dose (NFRLT) mutate( - EVID = 1, - NFRLT = case_when( - VISITDY == 1 ~ 0, - TRUE ~ 24 * VISITDY - ) + EVID = 1 + ) %>% + derive_var_nfrlt( + new_var = NFRLT, + new_var_unit = FRLTU, + out_unit = "HOURS", + visit_day = VISITDY ) %>% # Set missing end dates to start date mutate(AENDTM = case_when( @@ -230,8 +238,6 @@ adpc_first_dose <- pc_dates %>% ) ``` - - ```{r eval=TRUE, echo=FALSE, purl=FALSE} print_df(adpc_first_dose %>% select(USUBJID, FANLDTM, NFRLT, ADTM, AVISITN, AVISIT, PCTPT)) ``` @@ -318,7 +324,6 @@ adpc_nom_next <- adpc_nom_prev %>% print_df(adpc_nom_prev %>% select(USUBJID, NFRLT, AVISIT, PCTPT, NFRLT_prev)) ``` - ### Combine PC and EX Data Combine `PC` and `EX` records and derive the additional relative time variables. @@ -341,16 +346,17 @@ adpc_arrlt <- bind_rows(adpc_nom_next, ex_exp) %>% new_var = AFRLT, start_date = FANLDTM, end_date = ADTM, - out_unit = "hours", + out_unit = "HOURS", floor_in = FALSE, add_one = FALSE ) %>% # Derive Actual Relative Time from Reference Dose (ARRLT) derive_vars_duration( new_var = ARRLT, + new_var_unit = RRLTU, start_date = ADTM_prev, end_date = ADTM, - out_unit = "hours", + out_unit = "HOURS", floor_in = FALSE, add_one = FALSE ) %>% @@ -359,7 +365,7 @@ adpc_arrlt <- bind_rows(adpc_nom_next, ex_exp) %>% new_var = AXRLT, start_date = ADTM_next, end_date = ADTM, - out_unit = "hours", + out_unit = "HOURS", floor_in = FALSE, add_one = FALSE ) %>% @@ -406,12 +412,10 @@ adpc_nrrlt <- adpc_arrlt %>% ) ``` - ```{r eval=TRUE, echo=FALSE, purl=FALSE} print_df(adpc_nrrlt %>% select(USUBJID, NFRLT, NRRLT, AVISIT, PCTPT)) ``` - ### Derive Analysis Variables Here we derive the analysis variables such as `AVAL` and `ATPTREF`. @@ -458,8 +462,6 @@ adpc_aval <- adpc_nrrlt %>% ) %>% # Derive relative time units mutate( - FRLTU = "h", - RRLTU = "h", # Derive PARAMCD PARAMCD = coalesce(PCTESTCD, "DOSE"), ALLOQ = PCLLOQ, @@ -512,12 +514,10 @@ dtype <- adpc_aval %>% derive_vars_dtm_to_tm(exprs(PCRFTDTM)) ``` - ```{r eval=TRUE, echo=FALSE, purl=FALSE} print_df(dtype %>% select(USUBJID, DTYPE, BASETYPE, ATPT, NFRLT, NRRLT, AFRLT, ARRLT)) ``` - ### Combine Original and DTYPE Copy Now the duplicated records are combined with the original records. diff --git a/adam/adppk.R b/adam/adppk.R index 3842fb19..8e628673 100644 --- a/adam/adppk.R +++ b/adam/adppk.R @@ -59,8 +59,14 @@ pc_dates <- pc %>% # Derive event ID and nominal relative time from first dose (NFRLT) mutate( EVID = 0, - DRUG = PCTEST, - NFRLT = if_else(PCTPTNUM < 0, 0, PCTPTNUM), .after = USUBJID + DRUG = PCTEST + ) %>% + derive_var_nfrlt( + new_var = NFRLT, + new_var_unit = FRLTU, + out_unit = "HOURS", + tpt_var = PCTPT, + visit_day = VISITDY ) ## ----r------------------------------------------------------------------------ @@ -90,11 +96,13 @@ ex_dates <- ex %>% ) %>% # Derive event ID and nominal relative time from first dose (NFRLT) mutate( - EVID = 1, - NFRLT = case_when( - VISITDY == 1 ~ 0, - TRUE ~ 24 * VISITDY - ) + EVID = 1 + ) %>% + derive_var_nfrlt( + new_var = NFRLT, + new_var_unit = FRLTU, + out_unit = "HOURS", + visit_day = VISITDY ) %>% # Set missing end dates to start date mutate(AENDTM = case_when( @@ -211,7 +219,7 @@ adppk_aprlt <- bind_rows(adppk_nom_prev, ex_exp) %>% new_var = AFRLT, start_date = FANLDTM, end_date = ADTM, - out_unit = "hours", + out_unit = "HOURS", floor_in = FALSE, add_one = FALSE ) %>% @@ -220,7 +228,7 @@ adppk_aprlt <- bind_rows(adppk_nom_prev, ex_exp) %>% new_var = APRLT, start_date = ADTM_prev, end_date = ADTM, - out_unit = "hours", + out_unit = "HOURS", floor_in = FALSE, add_one = FALSE ) %>% diff --git a/adam/adppk.qmd b/adam/adppk.qmd index 5ceac193..242bff3e 100644 --- a/adam/adppk.qmd +++ b/adam/adppk.qmd @@ -73,7 +73,7 @@ lb <- convert_blanks_to_na(lb) ### Derive PC Dates -Here we use `{admiral}` functions for working with dates and we will also create a nominal time from first dose `NFRLT` for `PC` data based on `PCTPTNUM`. +Here we use `{admiral}` functions for working with dates and we will also create a nominal time from first dose `NFRLT` for `PC` data using `derive_var_nfrlt()`. ```{r} #| label: PC Dates @@ -103,8 +103,14 @@ pc_dates <- pc %>% # Derive event ID and nominal relative time from first dose (NFRLT) mutate( EVID = 0, - DRUG = PCTEST, - NFRLT = if_else(PCTPTNUM < 0, 0, PCTPTNUM), .after = USUBJID + DRUG = PCTEST + ) %>% + derive_var_nfrlt( + new_var = NFRLT, + new_var_unit = FRLTU, + out_unit = "HOURS", + tpt_var = PCTPT, + visit_day = VISITDY ) ``` @@ -115,7 +121,7 @@ print_df(pc_dates %>% select(USUBJID, PCTEST, ADTM, VISIT, PCTPT, NFRLT)) ### Get Dosing Information -Here we also create nominal time from first dose `NFRLT` for `EX` data based on `VISITDY`. +Here we also create nominal time from first dose `NFRLT` for `EX` data based on `VISITDY` using `derive_var_nfrlt()`. ```{r} #| label: Dosing @@ -145,11 +151,13 @@ ex_dates <- ex %>% ) %>% # Derive event ID and nominal relative time from first dose (NFRLT) mutate( - EVID = 1, - NFRLT = case_when( - VISITDY == 1 ~ 0, - TRUE ~ 24 * VISITDY - ) + EVID = 1 + ) %>% + derive_var_nfrlt( + new_var = NFRLT, + new_var_unit = FRLTU, + out_unit = "HOURS", + visit_day = VISITDY ) %>% # Set missing end dates to start date mutate(AENDTM = case_when( @@ -328,7 +336,7 @@ adppk_aprlt <- bind_rows(adppk_nom_prev, ex_exp) %>% new_var = AFRLT, start_date = FANLDTM, end_date = ADTM, - out_unit = "hours", + out_unit = "HOURS", floor_in = FALSE, add_one = FALSE ) %>% @@ -337,7 +345,7 @@ adppk_aprlt <- bind_rows(adppk_nom_prev, ex_exp) %>% new_var = APRLT, start_date = ADTM_prev, end_date = ADTM, - out_unit = "hours", + out_unit = "HOURS", floor_in = FALSE, add_one = FALSE ) %>% diff --git a/inst/WORDLIST b/inst/WORDLIST index a57298a7..4ee2a1e6 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -464,6 +464,7 @@ NCA nDate nDose nestcolor +nfrlt NFRLT nFrom nLTRs @@ -733,6 +734,7 @@ TMPTC toc topleft toupper +tpt TPT TPTNUM traceback