Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up example data modification #739

Merged
merged 7 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions R/tm_g_barchart_simple.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,11 @@
#' @export
#'
#' @examples
#' library(dplyr)
#' library(nestcolor)
#'
#' adsl <- tmc_ex_adsl %>%
#' dplyr::mutate(ITTFL = factor("Y"))
#' adae <- tmc_ex_adae
#'
#' adae_labels <- formatters::var_labels(adae, fill = FALSE)
#' adae <- adae %>% dplyr::filter(!((AETOXGR == 1) & (AESEV == "MILD") & (ARM == "A: Drug X")))
#'
#' # reinstate labels
#' formatters::var_labels(adae) <- adae_labels
#' adsl <- tmc_ex_adsl %>% dplyr::mutate(ITTFL = factor("Y") %>%
#' formatters::with_label("Intent-To-Treat Population Flag"))
#' adae <- tmc_ex_adae %>% dplyr::filter(!((AETOXGR == 1) & (AESEV == "MILD") & (ARM == "A: Drug X")))
#'
#' app <- init(
#' data = cdisc_data(
Expand Down
6 changes: 3 additions & 3 deletions R/tm_g_forest_rsp.R
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,13 @@ template_forest_rsp <- function(dataname = "ANL",
#' @template author_song24
#'
#' @examples
#' library(dplyr)
#' library(nestcolor)
#'
#' adsl <- tmc_ex_adsl
#' adrs <- tmc_ex_adrs %>%
#' mutate(AVALC = tern::d_onco_rsp_label(AVALC)) %>%
#' filter(PARAMCD != "OVRINV" | AVISIT == "FOLLOW UP")
#' dplyr::mutate(AVALC = tern::d_onco_rsp_label(AVALC) %>%
#' formatters::with_label("Character Result/Finding")) %>%
#' dplyr::filter(PARAMCD != "OVRINV" | AVISIT == "FOLLOW UP")
#'
#' arm_ref_comp <- list(
#' ARM = list(
Expand Down
3 changes: 1 addition & 2 deletions R/tm_g_forest_tte.R
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,7 @@ template_forest_tte <- function(dataname = "ANL",
#'
#' adsl <- tmc_ex_adsl
#' adtte <- tmc_ex_adtte
#'
#' adsl$RACE <- droplevels(adsl$RACE)
#' adsl$RACE <- droplevels(adsl$RACE) %>% formatters::with_label("Race")
#'
#' arm_ref_comp <- list(
#' ARM = list(
Expand Down
19 changes: 5 additions & 14 deletions R/tm_g_ipp.R
Original file line number Diff line number Diff line change
Expand Up @@ -186,27 +186,18 @@ template_g_ipp <- function(dataname = "ANL",
#' @export
#'
#' @examples
#' library(dplyr)
#' library(nestcolor)
#'
#' adsl <- tmc_ex_adsl %>% slice(1:20)
#' adlb <- tmc_ex_adlb
#' adlb <- adlb %>% filter(USUBJID %in% adsl$USUBJID)
#' adsl <- tmc_ex_adsl %>% dplyr::slice(1:20)
#' adlb <- tmc_ex_adlb %>% dplyr::filter(USUBJID %in% adsl$USUBJID)
#'
#' adsl <- df_explicit_na(adsl)
#' adlb <- df_explicit_na(adlb) %>%
#' dplyr::filter(AVISIT != "SCREENING")
#' adlb <- df_explicit_na(adlb) %>% dplyr::filter(AVISIT != "SCREENING")
#'
#' app <- init(
#' data = cdisc_data(
#' cdisc_dataset(
#' "ADSL",
#' adsl
#' ),
#' cdisc_dataset(
#' "ADLB",
#' adlb
#' )
#' cdisc_dataset("ADSL", adsl),
#' cdisc_dataset("ADLB", adlb)
#' ),
#' modules = modules(
#' tm_g_ipp(
Expand Down
2 changes: 1 addition & 1 deletion R/tm_g_km.R
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ template_g_km <- function(dataname = "ANL",
#' ),
#' modules = modules(
#' tm_g_km(
#' label = "KM PLOT",
#' label = "Kaplan-Meier Plot",
#' dataname = "ADTTE",
#' arm_var = choices_selected(
#' variable_choices(adsl, c("ARM", "ARMCD", "ACTARMCD")),
Expand Down
4 changes: 2 additions & 2 deletions R/tm_g_pp_adverse_events.R
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ template_adverse_events <- function(dataname = "ANL",
#' @examples
#' library(nestcolor)
#'
#' adsl <- tmc_ex_adsl
#' adae <- tmc_ex_adae
#' adsl <- tmc_ex_adsl %>% dplyr::filter(USUBJID %in% adae$USUBJID)
#'
#' app <- init(
#' data = cdisc_data(
Expand All @@ -192,7 +192,7 @@ template_adverse_events <- function(dataname = "ANL",
#' ),
#' modules = modules(
#' tm_g_pp_adverse_events(
#' label = "Adverse events",
#' label = "Adverse Events",
#' dataname = "ADAE",
#' parentname = "ADSL",
#' patient_col = "USUBJID",
Expand Down
37 changes: 15 additions & 22 deletions R/tm_g_pp_patient_timeline.R
Original file line number Diff line number Diff line change
Expand Up @@ -356,28 +356,21 @@ template_patient_timeline <- function(dataname = "ANL",
#' @examples
#' library(nestcolor)
#'
#' adsl <- tmc_ex_adsl
#' adae <- tmc_ex_adae
#' adcm <- tmc_ex_adcm
#'
#' # Modify ADCM
#' adcm$CMDOSE <- 1
#' adcm$CMDOSU <- "U"
#' adcm$CMROUTE <- "CMROUTE"
#' adcm$CMDOSFRQ <- "CMDOSFRQ"
#' adcm$CMSTDY <- 1
#' adcm[adcm$CMCAT == "medcl B", ]$CMSTDY <- 20
#' adcm[adcm$CMCAT == "medcl C", ]$CMSTDY <- 150
#' adcm$CMENDY <- 500
#' adcm[adcm$CMCAT == "medcl B", ]$CMENDY <- 700
#' adcm[adcm$CMCAT == "medcl C", ]$CMENDY <- 1000
#' adcm$CMASTDTM <- adcm$ASTDTM
#' adcm$CMAENDTM <- adcm$AENDTM
#' formatters::var_labels(adcm[c("CMINDC", "CMDECOD", "CMSTDY", "CMENDY")]) <- c(
#' "Indication",
#' "Reported Name of Drug, Med, or Therapy",
#' "Study Day of Start of Medication",
#' "Study Day of End of Medication"
#' adsl <- tmc_ex_adsl %>% dplyr::filter(USUBJID %in% adae$USUBJID)
#' adcm <- tmc_ex_adcm %>% dplyr::mutate(
#' CMSTDY = dplyr::case_when(
#' CMCAT == "medcl B" ~ 20,
#' CMCAT == "medcl C" ~ 150,
#' TRUE ~ 1
#' ) %>% formatters::with_label("Study Day of Start of Medication"),
#' CMENDY = dplyr::case_when(
#' CMCAT == "medcl B" ~ 700,
#' CMCAT == "medcl C" ~ 1000,
#' TRUE ~ 500
#' ) %>% formatters::with_label("Study Day of End of Medication"),
#' CMASTDTM = ASTDTM,
#' CMAENDTM = AENDTM
#' )
#' adcm_keys <- c("STUDYID", "USUBJID", "ASTDTM", "CMSEQ", "ATC1", "ATC2", "ATC3", "ATC4")
#'
Expand All @@ -389,7 +382,7 @@ template_patient_timeline <- function(dataname = "ANL",
#' ),
#' modules = modules(
#' tm_g_pp_patient_timeline(
#' label = "Patient timeline",
#' label = "Patient Timeline",
#' dataname_adae = "ADAE",
#' dataname_adcm = "ADCM",
#' parentname = "ADSL",
Expand Down
18 changes: 1 addition & 17 deletions R/tm_g_pp_therapy.R
Original file line number Diff line number Diff line change
Expand Up @@ -255,26 +255,10 @@ template_therapy <- function(dataname = "ANL",
#' @examples
#' library(nestcolor)
#'
#' adsl <- tmc_ex_adsl
#' adcm <- tmc_ex_adcm
#'
#' # Modify ADCM
#' adcm$CMINDC <- paste0("Indication_", as.numeric(adcm$CMDECOD))
#' adcm$CMDOSE <- 1
#' adcm$CMTRT <- adcm$CMCAT
#' adcm$CMDOSU <- "U"
#' adcm$CMROUTE <- "CMROUTE"
#' adcm$CMDOSFRQ <- "CMDOSFRQ"
#' adsl <- tmc_ex_adsl %>% dplyr::filter(USUBJID %in% adcm$USUBJID)
#' adcm$CMASTDTM <- adcm$ASTDTM
#' adcm$CMAENDTM <- adcm$AENDTM
#' formatters::var_labels(
#' adcm[c("CMINDC", "CMTRT", "ASTDY", "AENDY")]
#' ) <- c(
#' "Indication",
#' "Reported Name of Drug, Med, or Therapy",
#' "Study Day of Start of Medication",
#' "Study Day of End of Medication"
#' )
#' adcm_keys <- c("STUDYID", "USUBJID", "ASTDTM", "CMSEQ", "ATC1", "ATC2", "ATC3", "ATC4")
#'
#' app <- init(
Expand Down
10 changes: 3 additions & 7 deletions R/tm_t_abnormality.R
Original file line number Diff line number Diff line change
Expand Up @@ -232,19 +232,15 @@ template_abnormality <- function(parentname,
#'
#' @export
#' @examples
#' library(dplyr)
#'
#' adsl <- tmc_ex_adsl
#' adlb <- tmc_ex_adlb %>%
#' mutate(
#' ONTRTFL = case_when(
#' dplyr::mutate(
#' ONTRTFL = dplyr::case_when(
#' AVISIT %in% c("SCREENING", "BASELINE") ~ "",
#' TRUE ~ "Y"
#' )
#' ) %>% formatters::with_label("On Treatment Record Flag")
#' )
#'
#' attr(adlb[["ONTRTFL"]], "label") <- "On Treatment Record Flag"
#'
#' app <- init(
#' data = cdisc_data(
#' cdisc_dataset("ADSL", adsl),
Expand Down
6 changes: 2 additions & 4 deletions R/tm_t_abnormality_by_worst_grade.R
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,9 @@ template_abnormality_by_worst_grade <- function(parentname, # nolint
#' @export
#'
#' @examples
#' library(dplyr)
#'
#' adsl <- tmc_ex_adsl
#' adlb <- tmc_ex_adlb %>%
#' filter(!AVISIT %in% c("SCREENING", "BASELINE"))
#' dplyr::filter(!AVISIT %in% c("SCREENING", "BASELINE"))
#'
#' app <- init(
#' data = cdisc_data(
Expand All @@ -239,7 +237,7 @@ template_abnormality_by_worst_grade <- function(parentname, # nolint
#' ),
#' modules = modules(
#' tm_t_abnormality_by_worst_grade(
#' label = "Laboratory test results with highest grade post-baseline",
#' label = "Laboratory Test Results with Highest Grade Post-Baseline",
#' dataname = "ADLB",
#' arm_var = choices_selected(
#' choices = variable_choices(adsl, subset = c("ARM", "ARMCD")),
Expand Down
2 changes: 1 addition & 1 deletion R/tm_t_ancova.R
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ template_ancova <- function(dataname = "ANL",
#' ),
#' modules = modules(
#' tm_t_ancova(
#' label = "ANCOVA table",
#' label = "ANCOVA Table",
#' dataname = "ADQS",
#' avisit = choices_selected(
#' choices = value_choices(adqs, "AVISIT"),
Expand Down
10 changes: 6 additions & 4 deletions R/tm_t_binary_outcome.R
Original file line number Diff line number Diff line change
Expand Up @@ -391,12 +391,14 @@ template_binary_outcome <- function(dataname,
#' @export
#'
#' @examples
#' library(dplyr)
#'
#' adsl <- tmc_ex_adsl
#' adrs <- tmc_ex_adrs %>%
#' mutate(AVALC = d_onco_rsp_label(AVALC)) %>%
#' filter(PARAMCD != "OVRINV" | AVISIT == "FOLLOW UP")
#' dplyr::mutate(
#' AVALC = tern::d_onco_rsp_label(AVALC) %>%
#' formatters::with_label("Character Result/Finding")
#' ) %>%
#' dplyr::filter(PARAMCD != "OVRINV" | AVISIT == "FOLLOW UP")
#'
#' arm_ref_comp <- list(
#' ARMCD = list(ref = "ARM B", comp = c("ARM A", "ARM C")),
#' ARM = list(ref = "B: Placebo", comp = c("A: Drug X", "C: Combination"))
Expand Down
2 changes: 1 addition & 1 deletion R/tm_t_coxreg.R
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ template_coxreg_m <- function(dataname,
#' }
#'
#' The arm variables, stratification and covariate variables are taken from the
#' `ADSL` data.
#' ADSL data.
#'
#' @section Note:
#' - The likelihood ratio test is not supported for model including strata,
Expand Down
2 changes: 0 additions & 2 deletions R/tm_t_events.R
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,6 @@ template_events <- function(dataname,
#' @export
#'
#' @examples
#' library(dplyr)
#'
#' adsl <- tmc_ex_adsl
#' adae <- tmc_ex_adae
#'
Expand Down
7 changes: 3 additions & 4 deletions R/tm_t_events_by_grade.R
Original file line number Diff line number Diff line change
Expand Up @@ -777,12 +777,11 @@ template_events_col_by_grade <- function(dataname,
#'
#' @export
#' @examples
#' library(dplyr)
#' library(tern)
#'
#' adsl <- tmc_ex_adsl
#' lbls_adae <- formatters::var_labels(tmc_ex_adae)
#' adae <- tmc_ex_adae %>%
#' mutate_if(is.character, as.factor) # be certain of having factors
#' dplyr::mutate_if(is.character, as.factor) # be certain of having factors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this step drop labels?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shajoezhu yes, whenever mutate is used on a column the label is dropped.

#' formatters::var_labels(adae) <- lbls_adae
#'
#' app <- init(
#' data = cdisc_data(
Expand Down
10 changes: 3 additions & 7 deletions R/tm_t_events_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -491,17 +491,13 @@ template_events_summary <- function(anl_name,
#'
#' @export
#' @examples
#' library(dplyr)
#'
#' adsl <- tmc_ex_adsl %>%
#' mutate(
#' DTHFL = case_when( # nolint
#' dplyr::mutate(
#' DTHFL = dplyr::case_when( # nolint
#' !is.na(DTHDT) ~ "Y",
#' TRUE ~ ""
#' )
#' ) %>% formatters::with_label("Subject Death Flag")
#' )
#' attr(adsl[["DTHFL"]], "label") <- "Subject Death Flag"
#'
#' adae <- tmc_ex_adae
#'
#' add_event_flags <- function(dat) {
Expand Down
4 changes: 1 addition & 3 deletions R/tm_t_logistic.R
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,9 @@ template_logistic <- function(dataname,
#'
#' @export
#' @examples
#' library(dplyr)
#'
#' adsl <- tmc_ex_adsl
#' adrs <- tmc_ex_adrs %>%
#' filter(PARAMCD %in% c("BESRSPI", "INVET"))
#' dplyr::filter(PARAMCD %in% c("BESRSPI", "INVET"))
#'
#' arm_ref_comp <- list(
#' ACTARMCD = list(
Expand Down
2 changes: 0 additions & 2 deletions R/tm_t_mult_events.R
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,6 @@ template_mult_events <- function(dataname,
#' @export
#'
#' @examples
#' library(dplyr)
#'
#' adsl <- tmc_ex_adsl
#' adcm <- tmc_ex_adcm
#' adcm_keys <- c("STUDYID", "USUBJID", "ASTDTM", "CMSEQ", "ATC1", "ATC2", "ATC3", "ATC4")
Expand Down
2 changes: 1 addition & 1 deletion R/tm_t_pp_basic_info.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ template_basic_info <- function(dataname = "ANL",
#' ),
#' modules = modules(
#' tm_t_pp_basic_info(
#' label = "Basic info",
#' label = "Basic Info",
#' dataname = "ADSL",
#' patient_col = "USUBJID",
#' vars = choices_selected(
Expand Down
2 changes: 0 additions & 2 deletions R/tm_t_pp_laboratory.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ template_laboratory <- function(dataname = "ANL",
#' @export
#'
#' @examples
#'
#' # Reduced data for tests
#' adsl <- tmc_ex_adsl
#' adlb <- tmc_ex_adlb
#'
Expand Down
2 changes: 1 addition & 1 deletion R/tm_t_pp_medical_history.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ template_medical_history <- function(dataname = "ANL",
#' ),
#' modules = modules(
#' tm_t_pp_medical_history(
#' label = "Medical history",
#' label = "Medical History",
#' dataname = "ADMH",
#' parentname = "ADSL",
#' patient_col = "USUBJID",
Expand Down
Loading