diff --git a/.gitignore b/.gitignore index 5d68b430..3a2b1941 100644 --- a/.gitignore +++ b/.gitignore @@ -57,3 +57,5 @@ rsconnect/ # Markdown generated files */README.html +*/shiny_bookmarks +teal_app.lock diff --git a/RNA-seq/app.R b/RNA-seq/app.R index c5eeaaa1..4e97072e 100644 --- a/RNA-seq/app.R +++ b/RNA-seq/app.R @@ -13,7 +13,6 @@ data <- within(data, { dplyr::mutate(is_event = CNSR == 0) MAE <- hermes::multi_assay_experiment }) -datanames(data) <- c("ADTTE", "MAE") ## App header and footer ---- nest_logo <- "https://raw.githubusercontent.com/insightsengineering/hex-stickers/main/PNG/nest.png" diff --git a/early-dev/app.R b/early-dev/app.R index cb777512..ad2807ac 100644 --- a/early-dev/app.R +++ b/early-dev/app.R @@ -15,7 +15,7 @@ data <- within(data, { ADSL <- radsl(seed = 1) # derive ADSL treatment duration - adsl_labels <- teal.data::col_labels(ADSL, fill = FALSE) + .adsl_labels <- teal.data::col_labels(ADSL, fill = FALSE) ADSL <- ADSL %>% mutate( TRTDURD = as.numeric(as.Date(TRTEDTM) - as.Date(TRTSDTM)) + 1, @@ -29,12 +29,11 @@ data <- within(data, { EOSSTT = "End of Study Status" ) %>% droplevels() - teal.data::col_labels(ADSL)[c(names(adsl_labels))] <- adsl_labels + teal.data::col_labels(ADSL)[c(names(.adsl_labels))] <- .adsl_labels ADAE <- radae(ADSL, seed = 1) # derive common flags for AEs - adae_labels <- teal.data::col_labels(ADAE, fill = FALSE) ADAE <- ADAE %>% mutate_at(c("AESOC", "AEBODSYS", "AEHLT", "AEDECOD", "AETERM", "AELLT"), as.character) %>% mutate( @@ -93,7 +92,7 @@ data <- within(data, { ADTR <- radtr(ADSL, seed = 1) # process ADTR - adtr_labels <- teal.data::col_labels(ADTR, fill = FALSE) + .adtr_labels <- teal.data::col_labels(ADTR, fill = FALSE) ADTR <- ADTR %>% mutate( PCHG = ifelse(AVISIT == "BASELINE", 0, PCHG), @@ -102,7 +101,7 @@ data <- within(data, { AVALC = ifelse(AVISIT == "BASELINE", as.character(BASE), AVALC) ) %>% filter(AVISIT != "SCREENING") - teal.data::col_labels(ADTR) <- adtr_labels + teal.data::col_labels(ADTR) <- .adtr_labels ADTRWF <- ADTR %>% filter(AVISIT != "BASELINE") @@ -115,7 +114,6 @@ data <- within(data, { arrange(USUBJID) ADRS <- radrs(ADSL, seed = 1) - adrs_labels <- teal.data::col_labels(ADRS, fill = FALSE) ADRS <- ADRS %>% filter(PARAMCD %in% c("BESRSPI", "INVET")) %>% mutate(ADT = as.Date(ADTM)) %>% @@ -136,12 +134,10 @@ data <- within(data, { ) }) -# set datanames -datanames <- c("ADSL", "ADAE", "ADCM", "ADEX", "ADTR", "ADTRWF", "ADRS", "ADRSSWIM", "ADLB") -datanames(data) <- datanames - # set join keys -join_keys(data) <- default_cdisc_join_keys[datanames] # get default keys by name +join_keys(data) <- default_cdisc_join_keys[ + c("ADSL", "ADAE", "ADCM", "ADEX", "ADTR", "ADTRWF", "ADRS", "ADRSSWIM", "ADLB") +] # get default keys by name join_keys(data)["ADTR", "ADTR"] <- c("STUDYID", "USUBJID", "PARAMCD", "AVISIT") join_keys(data)["ADTRWF", "ADTRWF"] <- c("STUDYID", "USUBJID", "PARAMCD", "AVISIT") join_keys(data)["ADRSSWIM", "ADRSSWIM"] <- c("STUDYID", "USUBJID", "PARAMCD", "AVISIT") @@ -162,13 +158,8 @@ ADRSSWIM <- data[["ADRSSWIM"]] ADLB <- data[["ADLB"]] -adsl_labels <- teal.data::col_labels(ADSL) fact_vars_asl <- names(Filter(isTRUE, sapply(ADSL, is.factor))) -date_vars_asl <- - names(ADSL)[vapply(ADSL, function(x) inherits(x, c("Date", "POSIXct", "POSIXlt")), logical(1))] -demog_vars_asl <- names(ADSL)[!(names(ADSL) %in% c("USUBJID", "STUDYID", date_vars_asl))] - arm_vars <- c("ARMCD", "ARM", "ACTARMCD", "ACTARM", "EOSSTT") aeflag_vars <- c("RELFL", "CTC35FL", "SERFL", "RELSERFL") facet_vars <- c("SEX", "BMRKR2", "RACE", "STRATA1", "STRATA2") diff --git a/efficacy/app.R b/efficacy/app.R index 357c3212..5aa7a4fd 100644 --- a/efficacy/app.R +++ b/efficacy/app.R @@ -12,12 +12,12 @@ data <- within(data, { library(sparkline) ADSL <- radsl(seed = 1) - adsl_labels <- teal.data::col_labels(ADSL, fill = FALSE) + .adsl_labels <- teal.data::col_labels(ADSL, fill = FALSE) - char_vars_asl <- names(Filter(isTRUE, sapply(ADSL, is.character))) + .char_vars_asl <- names(Filter(isTRUE, sapply(ADSL, is.character))) - adsl_labels <- c( - adsl_labels, + .adsl_labels <- c( + .adsl_labels, AGEGR1 = "Age Group" ) ADSL <- ADSL %>% @@ -27,19 +27,19 @@ data <- within(data, { AGE >= 45 ~ ">=45" )) ) %>% - mutate_at(char_vars_asl, factor) + mutate_at(.char_vars_asl, factor) - teal.data::col_labels(ADSL) <- adsl_labels + teal.data::col_labels(ADSL) <- .adsl_labels ADTTE <- radtte(ADSL, seed = 1) ADRS <- radrs(ADSL, seed = 1) - adrs_labels <- teal.data::col_labels(ADRS, fill = FALSE) + .adrs_labels <- teal.data::col_labels(ADRS, fill = FALSE) ADRS <- filter(ADRS, PARAMCD == "BESRSPI" | AVISIT == "FOLLOW UP") - teal.data::col_labels(ADRS) <- adrs_labels + teal.data::col_labels(ADRS) <- .adrs_labels ADQS <- radqs(ADSL, seed = 1) - adqs_labels <- teal.data::col_labels(ADQS, fill = FALSE) + .adqs_labels <- teal.data::col_labels(ADQS, fill = FALSE) ADQS <- ADQS %>% filter(ABLFL != "Y" & ABLFL2 != "Y") %>% filter(AVISIT %in% c("WEEK 1 DAY 8", "WEEK 2 DAY 15", "WEEK 3 DAY 22")) %>% @@ -50,15 +50,11 @@ data <- within(data, { as.numeric() %>% as.factor() ) - teal.data::col_labels(ADQS) <- adqs_labels + teal.data::col_labels(ADQS) <- .adqs_labels }) -# set datanames -datanames <- c("ADSL", "ADTTE", "ADRS", "ADQS") -datanames(data) <- datanames - # set join_keys -join_keys(data) <- default_cdisc_join_keys[datanames] +join_keys(data) <- default_cdisc_join_keys[c("ADSL", "ADTTE", "ADRS", "ADQS")] ## Reusable Configuration For Modules ADSL <- data[["ADSL"]] diff --git a/exploratory/app.R b/exploratory/app.R index 51bfd15a..92e5746a 100644 --- a/exploratory/app.R +++ b/exploratory/app.R @@ -39,10 +39,7 @@ data <- within(data, { ) }) -datanames <- c("ADSL", "ADRS", "ADLB", "ADLBPCA") -datanames(data) <- datanames - -join_keys(data) <- default_cdisc_join_keys[datanames] +join_keys(data) <- default_cdisc_join_keys[c("ADSL", "ADRS", "ADLB", "ADLBPCA")] ## Reusable Configuration For Modules ADSL <- data[["ADSL"]] diff --git a/longitudinal/app.R b/longitudinal/app.R index a82c904b..2c3f04ff 100644 --- a/longitudinal/app.R +++ b/longitudinal/app.R @@ -31,12 +31,12 @@ data <- within(data, { # for example if biomarker is already log2 transformed then exclude # value of AVAL will then be assigned to XXXXXL2 variables. e.g. AVALL2 # e.g. if x assay is already log2 transformed then assigns AVAL to AVALL2 - exclude_l2 <- c("") + .exclude_l2 <- c("") # for example if study specific biomarker represents a CHG value then exclude # value NA is assigned to XXXXXL2. e.g. AVALL2 # e.g. if x assay are CHG values then assigns NA to AVALL2 - exclude_chg <- c("") + .exclude_chg <- c("") # the app expects ARM to be the main treatment variable # to use other treatment variables it is easiest to rename to ARM and process as ARM @@ -64,13 +64,13 @@ data <- within(data, { # convenience operator: create an operator that keeps the variable attributes # variable labels often get clobbered and we would like to keep them) - `%keep_label%` <- function(lhv, rhv) { + .keep_label <- function(lhv, rhv) { attributes(lhv) <- attributes(rhv) lhv } # convenience operator: create an operator that adds a label to newly created or re-processed variables - `%make_label%` <- function(lhv, label) { + .make_label <- function(lhv, label) { attr(lhv, "label") <- label lhv } @@ -86,10 +86,10 @@ data <- within(data, { TRT01P == "B: Placebo" ~ 3, TRUE ~ as.numeric(NA) ), - TRTORD = TRTORD %make_label% "Treatment Order", + TRTORD = .make_label(TRTORD, "Treatment Order"), TRT01P = as.character(arm_mapping[match(TRT01P, names(arm_mapping))]), TRT01P = factor(ARM) %>% reorder(TRTORD), - TRT01P = TRT01P %make_label% "Planned Treatment for Period 01" + TRT01P = .make_label(TRT01P, "Planned Treatment for Period 01") ) # capture state of variable labels to apply back onto variables after data filtering @@ -198,56 +198,60 @@ data <- within(data, { select(USUBJID, PARAMCD, AVAL) %>% group_by(PARAMCD) %>% summarise(AVAL_MIN = min(AVAL, na.rm = TRUE), .groups = "drop") %>% - mutate(PARAMCD = PARAMCD %make_label% "Parameter Code") + mutate(PARAMCD = .make_label(PARAMCD, "Parameter Code")) # post process the data to create several new variables and adjust existing record specific values per specification # - adjust existing BASELINE record values where values are missing ADLB_SUPED1 <- ADLB_SUBSET %>% - mutate(BASE2 = ifelse(toupper(AVISIT) == "SCREENING" & is.na(BASE2), AVAL, BASE2) %keep_label% BASE2) %>% - mutate(CHG2 = ifelse(toupper(AVISIT) == "SCREENING" & is.na(CHG2), 0, CHG2) %keep_label% CHG2) %>% - mutate(PCHG2 = ifelse(toupper(AVISIT) == "SCREENING" & is.na(PCHG2), 0, PCHG2) %keep_label% PCHG2) %>% - mutate(BASE = ifelse(toupper(AVISIT) == "BASELINE" & is.na(BASE), AVAL, BASE) %keep_label% BASE) %>% - mutate(CHG = ifelse(toupper(AVISIT) == "BASELINE" & is.na(CHG), 0, CHG) %keep_label% CHG) %>% - mutate(PCHG = ifelse(toupper(AVISIT) == "BASELINE" & is.na(PCHG), 0, PCHG) %keep_label% PCHG) %>% - mutate(TRTORD = TRTORD %make_label% "Treatment Order") + mutate(BASE2 = .keep_label(ifelse(toupper(AVISIT) == "SCREENING" & is.na(BASE2), AVAL, BASE2), BASE2)) %>% + mutate(CHG2 = .keep_label(ifelse(toupper(AVISIT) == "SCREENING" & is.na(CHG2), 0, CHG2), CHG2)) %>% + mutate(PCHG2 = .keep_label(ifelse(toupper(AVISIT) == "SCREENING" & is.na(PCHG2), 0, PCHG2), PCHG2)) %>% + mutate(BASE = .keep_label(ifelse(toupper(AVISIT) == "BASELINE" & is.na(BASE), AVAL, BASE), BASE)) %>% + mutate(CHG = .keep_label(ifelse(toupper(AVISIT) == "BASELINE" & is.na(CHG), 0, CHG), CHG)) %>% + mutate(PCHG = .keep_label(ifelse(toupper(AVISIT) == "BASELINE" & is.na(PCHG), 0, PCHG), PCHG)) %>% + mutate(TRTORD = .make_label(TRTORD, "Treatment Order")) # Inconsequential Warning issued: Warning: "PARAMCD" has different attributes on LHS and RHS of join. # merge minimum AVAL value onto the ADLB data to calculate the log2 variables. preserve the variable order ADLB_SUPED2 <- inner_join(PARAM_MINS, ADLB_SUPED1, by = "PARAMCD")[, union(names(ADLB_SUPED1), names(PARAM_MINS))] %>% # visit values # excludes biomarkers where log2 is not appropriate: for example assay value already log2 - mutate(AVALL2 = ifelse(PARAMCD %in% exclude_l2, AVAL, - # excludes biomarkers where log2 is not appropriate: for example CHG type assay - ifelse(PARAMCD %in% exclude_chg, NA, - ifelse(AVAL == 0 & AVAL_MIN > 0, log2(AVAL_MIN / 2), - # would be taking log2 of 0 or negative value so set to NA - ifelse(AVAL == 0 & AVAL_MIN <= 0, NA, - ifelse(AVAL > 0, log2(AVAL), NA) + mutate(AVALL2 = .make_label( + ifelse(PARAMCD %in% .exclude_l2, AVAL, + # excludes biomarkers where log2 is not appropriate: for example CHG type assay + ifelse(PARAMCD %in% .exclude_chg, NA, + ifelse(AVAL == 0 & AVAL_MIN > 0, log2(AVAL_MIN / 2), + # would be taking log2 of 0 or negative value so set to NA + ifelse(AVAL == 0 & AVAL_MIN <= 0, NA, + ifelse(AVAL > 0, log2(AVAL), NA) + ) ) ) - ) - ) %make_label% "Log2 of AVAL") %>% + ), "Log2 of AVAL" + )) %>% # baseline values - mutate(BASEL2 = ifelse(PARAMCD %in% exclude_l2, BASE, - ifelse(PARAMCD %in% exclude_chg, NA, + mutate(BASEL2 = .make_label(ifelse(PARAMCD %in% .exclude_l2, BASE, + ifelse(PARAMCD %in% .exclude_chg, NA, ifelse(BASE == 0 & AVAL_MIN > 0, log2(AVAL_MIN / 2), ifelse(BASE == 0 & AVAL_MIN <= 0, NA, ifelse(BASE > 0, log2(BASE), NA) ) ) ) - ) %make_label% "Log2 of BASE") %>% + ), "Log2 of BASE")) %>% # screening - mutate(BASE2L2 = ifelse(PARAMCD %in% exclude_l2, BASE2, - ifelse(PARAMCD %in% exclude_chg, NA, - ifelse(BASE2 == 0 & AVAL_MIN > 0, log2(AVAL_MIN / 2), - ifelse(BASE2 == 0 & AVAL_MIN <= 0, NA, - ifelse(BASE2 > 0, log2(BASE2), NA) + mutate(BASE2L2 = .make_label( + ifelse(PARAMCD %in% .exclude_l2, BASE2, + ifelse(PARAMCD %in% .exclude_chg, NA, + ifelse(BASE2 == 0 & AVAL_MIN > 0, log2(AVAL_MIN / 2), + ifelse(BASE2 == 0 & AVAL_MIN <= 0, NA, + ifelse(BASE2 > 0, log2(BASE2), NA) + ) ) ) - ) - ) %make_label% "Log2 of BASE2") %>% - mutate(AVAL_MIN = AVAL_MIN %make_label% "Minimum AVAL Within PARAMCD") + ), "Log2 of BASE2" + )) %>% + mutate(AVAL_MIN = .make_label(AVAL_MIN, "Minimum AVAL Within PARAMCD")) # create final data set used by goshawk # all data set passed into a goshawk app must have all of the columns @@ -255,15 +259,15 @@ data <- within(data, { ADLB <- ADLB_SUPED2 %>% mutate( TRT01P = as.character(arm_mapping[match(TRT01P, names(arm_mapping))]), - TRT01P = factor(TRT01P) %>% reorder(TRTORD) %make_label% "Planned Treatment for Period 01", + TRT01P = .make_label(factor(TRT01P) %>% reorder(TRTORD), "Planned Treatment for Period 01"), TRT01A = as.character(arm_mapping[match(TRT01A, names(arm_mapping))]), - TRT01A = factor(TRT01A) %>% reorder(TRTORD) %make_label% "Actual Treatment for Period 01", - LOQFL = LOQFL %make_label% "Limit of Quantification", - AVISITCD = factor(AVISITCD) %>% reorder(AVISITCDN) %make_label% "Analysis Visit Window Code", - AVISITCDN = AVISITCDN %make_label% "Analysis Visit Window Code (N)", - BASE2 = BASE2 %make_label% "Screening Value", - CHG2 = CHG2 %make_label% "Absolute Change from Screening", - PCHG2 = PCHG2 %make_label% "Percent Change from Screening" + TRT01A = .make_label(factor(TRT01A) %>% reorder(TRTORD), "Actual Treatment for Period 01"), + LOQFL = .make_label(LOQFL, "Limit of Quantification"), + AVISITCD = .make_label(factor(AVISITCD) %>% reorder(AVISITCDN), "Analysis Visit Window Code"), + AVISITCDN = .make_label(AVISITCDN, "Analysis Visit Window Code (N)"), + BASE2 = .make_label(BASE2, "Screening Value"), + CHG2 = .make_label(CHG2, "Absolute Change from Screening"), + PCHG2 = .make_label(PCHG2, "Percent Change from Screening") ) # add LLOQ and ULOQ variables to support adding horizontal/vertical range lines @@ -279,15 +283,13 @@ data <- within(data, { ################################################################################ }) -datanames <- c("ADSL", "ADLB") -datanames(data) <- datanames -join_keys(data) <- default_cdisc_join_keys[datanames] +join_keys(data) <- default_cdisc_join_keys[c("ADSL", "ADLB")] ## App configuration ---- ADSL <- data[["ADSL"]] ADLB <- data[["ADLB"]] -exclude_l2 <- data[["exclude_l2"]] -exclude_chg <- data[["exclude_chg"]] +.exclude_l2 <- data[[".exclude_l2"]] +.exclude_chg <- data[[".exclude_chg"]] # study information: used to label app and in "Example Info Page" module ATYPE <- "Exploratory" # define here and in the "# code >" section below @@ -408,7 +410,7 @@ paramcd_list <- paramDict$PARAMCD # create list of biomarkers excluded from log2 transformation paramexcldDict <- paramDict %>% - filter(PARAMCD %in% c(exclude_l2, exclude_chg)) + filter(PARAMCD %in% c(.exclude_l2, .exclude_chg)) paramexcld_list <- paramexcldDict$PARAM paramcdexcld_list <- paramexcldDict$PARAMCD @@ -775,29 +777,4 @@ app <- teal::init( ) ) -# Add context sensitive help code -body(app$server)[[length(body(app$server)) + 1]] <- quote( - observeEvent(input$showAnlVarLegendModal, { - showModal(modalDialog( - title = "Analysis Variable Pull Down Menu", - tags$p( - "These variables will appear in the Visualizations 'Analysis Variable' pull down menu. This legend - provides the variable labels to help clarify the short analysis variable names displayed in the pull down - menu." - ), - p("BASE2 = Screening Visit Value"), - p("BASE2L2 = Log2(BASE2)"), - p("CHG2 = Change from Screening"), - p("PCHG2 = % Change from Screening"), - p("BASE = Baseline Visit Value"), - p("BASEL2 = Log2(BASE)"), - p("CHG = Change from Baseline"), - p("PCHG = % Change from Baseline"), - p("AVAL = Visit Values"), - p("AVALL2 = Log2(AVAL)"), - easyClose = TRUE - )) - }) -) - shinyApp(app$ui, app$server) diff --git a/patient-profile/app.R b/patient-profile/app.R index 2c7538e6..87ffe2fa 100644 --- a/patient-profile/app.R +++ b/patient-profile/app.R @@ -39,9 +39,7 @@ data <- within(data, { teal.data::col_labels(ADMH[c("MHDISTAT")]) <- c("Status of Disease") }) -datanames <- c("ADSL", "ADMH", "ADAE", "ADCM", "ADVS", "ADLB") -datanames(data) <- datanames -join_keys(data) <- default_cdisc_join_keys[datanames] +join_keys(data) <- default_cdisc_join_keys[c("ADSL", "ADMH", "ADAE", "ADCM", "ADVS", "ADLB")] ## App configuration ---- ADSL <- data[["ADSL"]] diff --git a/python/app.R b/python/app.R index 114e0185..f3fe1398 100644 --- a/python/app.R +++ b/python/app.R @@ -25,20 +25,20 @@ data <- teal_data_module( teal_data(), " library(reticulate) - python_dependencies <- c(\"pip\", \"numpy\", \"pandas\") # @linksto py_dict - virtualenv_dir <- Sys.getenv(\"VIRTUALENV_NAME\", \"example_env_name\") # @linksto py_dict - python_path <- Sys.getenv(\"PYTHON_PATH\") # @linksto py_dict - if (python_path == \"\") python_path <- NULL + .python_dependencies <- c(\"pip\", \"numpy\", \"pandas\") # @linksto .py_dict + .virtualenv_dir <- Sys.getenv(\"VIRTUALENV_NAME\", \"example_env_name\") # @linksto .py_dict + .python_path <- Sys.getenv(\"PYTHON_PATH\") # @linksto .py_dict + if (.python_path == \"\") .python_path <- NULL reticulate::virtualenv_create( - envname = virtualenv_dir, python = python_path - ) # @linksto py_dict + envname = .virtualenv_dir, python = .python_path + ) # @linksto .py_dict reticulate::virtualenv_install( - virtualenv_dir, - packages = python_dependencies, + .virtualenv_dir, + packages = .python_dependencies, ignore_installed = TRUE - ) # @linksto py_dict - reticulate::use_virtualenv(virtualenv_dir, required = TRUE) # @linksto py_dict - iris_raw <- cbind(id = seq_len(nrow(iris)), iris) # @linksto py_dict + ) # @linksto .py_dict + reticulate::use_virtualenv(.virtualenv_dir, required = TRUE) # @linksto .py_dict + iris_raw <- cbind(id = seq_len(nrow(iris)), iris) # @linksto .py_dict " ) @@ -47,35 +47,34 @@ data <- teal_data_module( data, { # python code needs to be un-indented - python_code <- " -import pandas as pd -data = r.iris_raw -def svd_whiten(dat): - import numpy as np - X = np.matrix(dat) - U, s, Vt = np.linalg.svd(X, full_matrices=False) - X_white = np.dot(U, Vt) - return X_white + .python_code <- " + import pandas as pd + data = r.iris_raw + def svd_whiten(dat): + import numpy as np + X = np.matrix(dat) + U, s, Vt = np.linalg.svd(X, full_matrices=False) + X_white = np.dot(U, Vt) + return X_white -data_columns = data.columns -global numeric_cols_ix -global numeric_cols -numeric_cols_ix = list(range(5))[1:] -numeric_cols = [x for i,x in enumerate(data_columns) if i in numeric_cols_ix] -svd_res = svd_whiten(data.iloc[:, numeric_cols_ix]) -data_new = pd.concat([data, pd.DataFrame(svd_res)], axis = 1) -data_new.columns = list(data_columns) + [i + '.whiten' for i in numeric_cols] -data_new = data_new.round(10) -data_new + data_columns = data.columns + global numeric_cols_ix + global numeric_cols + numeric_cols_ix = list(range(5))[1:] + numeric_cols = [x for i,x in enumerate(data_columns) if i in numeric_cols_ix] + svd_res = svd_whiten(data.iloc[:, numeric_cols_ix]) + data_new = pd.concat([data, pd.DataFrame(svd_res)], axis = 1) + data_new.columns = list(data_columns) + [i + '.whiten' for i in numeric_cols] + data_new = data_new.round(10) + data_new " withr::with_options( list(reticulate.engine.environment = environment()), - py_dict <- py_run_string(python_code) + .py_dict <- py_run_string(.python_code) ) - IRIS <- py_dict$data_new + IRIS <- .py_dict$data_new } ) - datanames(data) <- c("IRIS") data }) }) diff --git a/safety/app.R b/safety/app.R index aaa3ec12..3585fd26 100644 --- a/safety/app.R +++ b/safety/app.R @@ -25,21 +25,18 @@ data <- within(data, { )) %>% teal.data::col_relabel(is_event = "Is an Event") %>% teal.data::col_relabel(n_events = "Number of Events") - ADAETTE_AE <- - filter(ADAETTE, grepl("TOT", .data$PARAMCD, fixed = TRUE)) %>% select(-"AVAL") - ADAETTE_OTH <- - filter(ADAETTE, !(grepl("TOT", .data$PARAMCD, fixed = TRUE))) + .ADAETTE_AE <- filter(ADAETTE, grepl("TOT", .data$PARAMCD, fixed = TRUE)) %>% select(-"AVAL") + .ADAETTE_OTH <- filter(ADAETTE, !(grepl("TOT", .data$PARAMCD, fixed = TRUE))) - ADAETTE_TTE <- ADAETTE %>% + .ADAETTE_TTE <- ADAETTE %>% filter(PARAMCD == "AEREPTTE") %>% select(USUBJID, ARM, ARMCD, AVAL) - ADAETTE_AE <- - full_join(ADAETTE_AE, ADAETTE_TTE, by = c("USUBJID", "ARM", "ARMCD")) - ADAETTE <- rbind(ADAETTE_AE, ADAETTE_OTH) + .ADAETTE_AE <- full_join(.ADAETTE_AE, .ADAETTE_TTE, by = c("USUBJID", "ARM", "ARMCD")) + ADAETTE <- rbind(.ADAETTE_AE, .ADAETTE_OTH) ADEX <- radex(ADSL, seed = 1) - ADEX_labels <- teal.data::col_labels(ADEX, fill = FALSE) + .ADEX_labels <- teal.data::col_labels(ADEX, fill = FALSE) # Below steps are done to simulate data with TDURD parameter as it is not in the ADEX data from `random.cdisc.data` package set.seed(1, kind = "Mersenne-Twister") ADEX <- ADEX %>% @@ -59,7 +56,7 @@ data <- within(data, { ADEX <- ADEX %>% filter(PARCAT1 == "OVERALL" & PARAMCD %in% c("TDOSE", "TNDOSE", "TDURD")) - teal.data::col_labels(ADEX) <- ADEX_labels + teal.data::col_labels(ADEX) <- .ADEX_labels ADLB <- radlb(ADSL, seed = 1) @@ -95,7 +92,7 @@ data <- within(data, { # tern::df_explicit_na(omit_columns = setdiff(names(ADEX), c("PARAM", "PARAMCD", "PARCAT2") )) # define study-specific analysis subgroups and baskets from ADAE - add_event_flags <- function(dat) { + .add_event_flags <- function(dat) { dat %>% dplyr::mutate( TMPFL_SER = AESER == "Y", @@ -116,12 +113,10 @@ data <- within(data, { } ADAE <- ADAE %>% - add_event_flags() + .add_event_flags() }) -datanames <- c("ADSL", "ADAE", "ADAETTE", "ADEX", "ADLB", "ADEG", "ADVS", "ADCM") -datanames(data) <- datanames -join_keys(data) <- default_cdisc_join_keys[datanames] +join_keys(data) <- default_cdisc_join_keys[c("ADSL", "ADAE", "ADAETTE", "ADEX", "ADLB", "ADEG", "ADVS", "ADCM")] ## App configuration ---- ADSL <- data[["ADSL"]]