From eb9030a10797c2ff54ec662c0e37299de73bb6fe Mon Sep 17 00:00:00 2001 From: elong0527 Date: Mon, 18 Aug 2025 21:40:41 -0400 Subject: [PATCH] Apply code formatting updates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Format R code for consistent style - Update documentation formatting - Format vignettes for consistency - Improve code readability with proper spacing and indentation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- R/ae_forestly.R | 23 +- R/ae_listing.R | 347 ++++++++++---------- R/format_ae_forestly.R | 16 +- R/prepare_ae_forestly.R | 36 +- R/reactable2.R | 22 +- data-raw/forestly_adae.R | 27 +- man/format_ae_forestly.Rd | 6 +- man/prepare_ae_forestly.Rd | 4 +- vignettes/customize-ae-specific-columns.Rmd | 58 ++-- vignettes/customize-color.Rmd | 58 ++-- vignettes/customize-diff-label.Rmd | 60 ++-- vignettes/customize-digits.Rmd | 58 ++-- vignettes/customize-listing-columns.Rmd | 58 ++-- vignettes/customize-width.Rmd | 78 +++-- vignettes/customize-xlimit.Rmd | 58 ++-- vignettes/forestly.Rmd | 80 +++-- 16 files changed, 554 insertions(+), 435 deletions(-) diff --git a/R/ae_forestly.R b/R/ae_forestly.R index 7896520..d59b1a9 100644 --- a/R/ae_forestly.R +++ b/R/ae_forestly.R @@ -44,7 +44,6 @@ #' format_ae_forestly() |> #' ae_forestly() #' } - ae_forestly <- function(outdata, display_soc_toggle = TRUE, filter = c("prop", "n"), @@ -90,8 +89,9 @@ ae_forestly <- function(outdata, if (is.null(filter_label)) { filter_label <- ifelse(filter == "prop", - "Incidence (%) in One or More Treatment Groups", - "Number of AE in One or More Treatment Groups") + "Incidence (%) in One or More Treatment Groups", + "Number of AE in One or More Treatment Groups" + ) } # `max_page` controls the maximum page number displayed in the interactive forest table. @@ -108,13 +108,15 @@ ae_forestly <- function(outdata, FUN.VALUE = character(1) ) - for (par in parameters[(!(parameters %in% unique(outdata$parameter_order)))]){ + for (par in parameters[(!(parameters %in% unique(outdata$parameter_order)))]) { outdata$tbl <- rbind(outdata$tbl, NA) outdata$tbl$name <- ifelse(is.na(outdata$tbl$name), "No data to display", outdata$tbl$name) outdata$tbl$parameter <- - factor(ifelse(is.na(outdata$tbl$parameter), par, as.character(outdata$tbl$parameter)), - levels(outdata$parameter_order)) + factor( + ifelse(is.na(outdata$tbl$parameter), par, as.character(outdata$tbl$parameter)), + levels(outdata$parameter_order) + ) } outdata$tbl$parameter <- factor( @@ -191,8 +193,8 @@ ae_forestly <- function(outdata, outdata$ae_listing, ((toupper(outdata$ae_listing$Adverse_Event) %in% toupper(t_row)) & (outdata$ae_listing$param == t_param)) | - ((toupper(outdata$ae_listing$SOC_Name) %in% toupper(t_row)) & - (outdata$ae_listing$param == t_param)) + ((toupper(outdata$ae_listing$SOC_Name) %in% toupper(t_row)) & + (outdata$ae_listing$param == t_param)) ) # Exclude 'param' column from t_details @@ -217,9 +219,9 @@ ae_forestly <- function(outdata, col_defs <- stats::setNames( lapply(names(t_details), function(name) { # Use label from the list - label_name <- if(is.null(labels[[name]])) name else labels[[name]][[1]] + label_name <- if (is.null(labels[[name]])) name else labels[[name]][[1]] reactable::colDef( - header = label_name, # Use header instead of name + header = label_name, # Use header instead of name cell = function(value) format(value, nsmall = 1), align = "center", minWidth = 70 @@ -242,7 +244,6 @@ ae_forestly <- function(outdata, highlight = TRUE ) }, - pageSizeOptions = max_page, # Default sort variable diff --git a/R/ae_listing.R b/R/ae_listing.R index 25f7330..44e51df 100644 --- a/R/ae_listing.R +++ b/R/ae_listing.R @@ -101,208 +101,217 @@ propercase <- function(x) paste0(toupper(substr(x, 1, 1)), tolower(substring(x, #' lapply(outdata, head, 20) format_ae_listing <- function(outdata, display_unique_records = FALSE) { res <- outdata[["ae_listing"]] -obs_group <- metalite::collect_adam_mapping(outdata$meta, outdata$observation)$group -par_var <- metalite::collect_adam_mapping(outdata$meta, outdata$parameter)$var -par_var_soc <- metalite::collect_adam_mapping(outdata$meta, outdata$parameter)$soc - -new_name <- c("SITEID", "SITENUM", "USUBJID", "SUBJID", "SEX", "RACE", "AGE", obs_group, "EPOCH", - "ASTDY", par_var, par_var_soc, "ADURN", "AESEV", "AESER", "AEREL", "AREL", "AEACN", - "AEOUT", "AEDOSDUR", "ATOXGRN") -name_mapping <- c("Site_Number", "Site_Number", "Unique_Participant_ID", "Participant_ID", "Gender", "Race", "Age", "Treatment_Group", "Onset_Epoch", - "Relative_Day_of_Onset", "Adverse_Event", "SOC_Name", "Duration", "Intensity", "Serious", "Related", "Related", "Action_Taken", - "Outcome", "Total_Dose_on_Day_of_AE_Onset", "Maximum_Toxicity_Grade") -names(name_mapping) <- new_name - -res_columns <- lapply(names(res), function(x) { - if (toupper(x) %in% names(name_mapping)) {name_mapping[[toupper(x)]]} - else {x} -}) |> unlist() - -# Site ID -if ("SITEID" %in% toupper(names(res))) { - res[["Site_Number"]] <- propercase(res[["SITEID"]]) -} + obs_group <- metalite::collect_adam_mapping(outdata$meta, outdata$observation)$group + par_var <- metalite::collect_adam_mapping(outdata$meta, outdata$parameter)$var + par_var_soc <- metalite::collect_adam_mapping(outdata$meta, outdata$parameter)$soc -if ("SITENUM" %in% toupper(names(res))) { - res[["Site_Number"]] <- res[["SITENUM"]] -} + new_name <- c( + "SITEID", "SITENUM", "USUBJID", "SUBJID", "SEX", "RACE", "AGE", obs_group, "EPOCH", + "ASTDY", par_var, par_var_soc, "ADURN", "AESEV", "AESER", "AEREL", "AREL", "AEACN", + "AEOUT", "AEDOSDUR", "ATOXGRN" + ) + name_mapping <- c( + "Site_Number", "Site_Number", "Unique_Participant_ID", "Participant_ID", "Gender", "Race", "Age", "Treatment_Group", "Onset_Epoch", + "Relative_Day_of_Onset", "Adverse_Event", "SOC_Name", "Duration", "Intensity", "Serious", "Related", "Related", "Action_Taken", + "Outcome", "Total_Dose_on_Day_of_AE_Onset", "Maximum_Toxicity_Grade" + ) + names(name_mapping) <- new_name -# Participant ID -if ("USUBJID" %in% toupper(names(res))) { - res[["Unique_Participant_ID"]] <- res[["USUBJID"]] -} -if ("SUBJID" %in% toupper(names(res))) { - res[["Participant_ID"]] <- res[["SUBJID"]] -} -attr(res[["Participant_ID"]], "label") <- NULL + res_columns <- lapply(names(res), function(x) { + if (toupper(x) %in% names(name_mapping)) { + name_mapping[[toupper(x)]] + } else { + x + } + }) |> unlist() + + # Site ID + if ("SITEID" %in% toupper(names(res))) { + res[["Site_Number"]] <- propercase(res[["SITEID"]]) + } + + if ("SITENUM" %in% toupper(names(res))) { + res[["Site_Number"]] <- res[["SITENUM"]] + } -res[["Gender"]] <- tools::toTitleCase(res[["SEX"]]) + # Participant ID + if ("USUBJID" %in% toupper(names(res))) { + res[["Unique_Participant_ID"]] <- res[["USUBJID"]] + } + if ("SUBJID" %in% toupper(names(res))) { + res[["Participant_ID"]] <- res[["SUBJID"]] + } + attr(res[["Participant_ID"]], "label") <- NULL -res[["Race"]] <- tools::toTitleCase(tolower(res[["RACE"]])) + res[["Gender"]] <- tools::toTitleCase(res[["SEX"]]) -res[["Age"]] <- res[["AGE"]] + res[["Race"]] <- tools::toTitleCase(tolower(res[["RACE"]])) -res[["Treatment_Group"]] <- res[[obs_group]] + res[["Age"]] <- res[["AGE"]] -attr(res[["Treatment_Group"]], "label") <- NULL + res[["Treatment_Group"]] <- res[[obs_group]] -# Onset epoch -if ("EPOCH" %in% toupper(names(res))) { - res[["Onset_Epoch"]] <- tools::toTitleCase(tolower(res[["EPOCH"]])) # propcase the EPOCH -} + attr(res[["Treatment_Group"]], "label") <- NULL + # Onset epoch + if ("EPOCH" %in% toupper(names(res))) { + res[["Onset_Epoch"]] <- tools::toTitleCase(tolower(res[["EPOCH"]])) # propcase the EPOCH + } -# Relative day of onset (ASTDY) -if ("ASTDY" %in% toupper(names(res))) { - res[["Relative_Day_of_Onset"]] <- res[["ASTDY"]] -} -# SOC -res[["SOC_Name"]] <- res[[par_var_soc]] - -# Adverse event -res[["Adverse_Event"]] <- propercase(res[[par_var]]) -res <- res[, !(names(res) == par_var)] - -# Duration -if ("ADURN" %in% toupper(names(res)) & "ADURU" %in% toupper(names(res))) { - res[["Duration"]] <- paste(ifelse(is.na(res[["ADURN"]]), "", as.character(res[["ADURN"]])), - tools::toTitleCase(tolower(res[["ADURU"]])), - sep = " ") # AE duration with unit - - if (length(res[["Duration"]]) > 0) { - for (i in 1:length(res[["Duration"]])) { - if (is.na(res[["ADURN"]][i])) { - res[["Duration"]][i] <- ifelse(charmatch(toupper(res[["AEOUT"]][i]), "RECOVERING/RESOLVING") > 0 | - charmatch(toupper(res[["AEOUT"]][i]), "NOT RECOVERED/NOT RESOLVED") > 0, - "Continuing", "Unknown") + # Relative day of onset (ASTDY) + if ("ASTDY" %in% toupper(names(res))) { + res[["Relative_Day_of_Onset"]] <- res[["ASTDY"]] + } + + # SOC + res[["SOC_Name"]] <- res[[par_var_soc]] + + # Adverse event + res[["Adverse_Event"]] <- propercase(res[[par_var]]) + res <- res[, !(names(res) == par_var)] + + # Duration + if ("ADURN" %in% toupper(names(res)) & "ADURU" %in% toupper(names(res))) { + res[["Duration"]] <- paste(ifelse(is.na(res[["ADURN"]]), "", as.character(res[["ADURN"]])), + tools::toTitleCase(tolower(res[["ADURU"]])), + sep = " " + ) # AE duration with unit + + if (length(res[["Duration"]]) > 0) { + for (i in 1:length(res[["Duration"]])) { + if (is.na(res[["ADURN"]][i])) { + res[["Duration"]][i] <- ifelse(charmatch(toupper(res[["AEOUT"]][i]), "RECOVERING/RESOLVING") > 0 | + charmatch(toupper(res[["AEOUT"]][i]), "NOT RECOVERED/NOT RESOLVED") > 0, + "Continuing", "Unknown" + ) + } } } + res <- res[, !(names(res) %in% "ADURU")] + res_columns <- res_columns[!(res_columns %in% "ADURU")] } -res <- res[,!(names(res) %in% "ADURU")] -res_columns <- res_columns[!(res_columns %in% "ADURU")] -} -# Intensity -if ("AESEV" %in% toupper(names(res))) { - res[["Intensity"]] <- propercase(res[["AESEV"]]) -} + # Intensity + if ("AESEV" %in% toupper(names(res))) { + res[["Intensity"]] <- propercase(res[["AESEV"]]) + } -# Maximum toxicity grade -if ("ATOXGRN" %in% toupper(names(res))) { - res[["Maximum_Toxicity_Grade"]] <- res[["ATOXGRN"]] -} + # Maximum toxicity grade + if ("ATOXGRN" %in% toupper(names(res))) { + res[["Maximum_Toxicity_Grade"]] <- res[["ATOXGRN"]] + } -# Serious -if ("AESER" %in% toupper(names(res))) { - res[["Serious"]] <- propercase(res[["AESER"]]) -} + # Serious + if ("AESER" %in% toupper(names(res))) { + res[["Serious"]] <- propercase(res[["AESER"]]) + } -# AE related -if ("AEREL" %in% toupper(names(res))) { - res[["Related"]] <- ifelse(res[["AEREL"]] == "RELATED", "Y", ifelse( - toupper(res[["AEREL"]]) == "NOT RELATED", "N", tools::toTitleCase(tolower(res[["AEREL"]])) - )) -} + # AE related + if ("AEREL" %in% toupper(names(res))) { + res[["Related"]] <- ifelse(res[["AEREL"]] == "RELATED", "Y", ifelse( + toupper(res[["AEREL"]]) == "NOT RELATED", "N", tools::toTitleCase(tolower(res[["AEREL"]])) + )) + } -# Action taken -if ("AEACN" %in% toupper(names(res))) { - if (length(res[["AEACN"]]) > 0) { - for (i in 1:length(res[["AEACN"]])) { - res[["Action_Taken"]][i] <- switch(res[["AEACN"]][i], - "DOSE NOT CHANGED" = "None", - "DOSE REDUCED" = "Reduced", - "DRUG INTERRUPTED" = "Interrupted", - "DOSE INCREASED" = "Increased", - "NOT APPLICABLE" = "N/A", - "UNKNOWN" = "Unknown", - tools::toTitleCase(tolower(res[["AEACN"]][i])) - ) + # Action taken + if ("AEACN" %in% toupper(names(res))) { + if (length(res[["AEACN"]]) > 0) { + for (i in 1:length(res[["AEACN"]])) { + res[["Action_Taken"]][i] <- switch(res[["AEACN"]][i], + "DOSE NOT CHANGED" = "None", + "DOSE REDUCED" = "Reduced", + "DRUG INTERRUPTED" = "Interrupted", + "DOSE INCREASED" = "Increased", + "NOT APPLICABLE" = "N/A", + "UNKNOWN" = "Unknown", + tools::toTitleCase(tolower(res[["AEACN"]][i])) + ) + } + } else { + res[["Action_Taken"]] <- res[["AEACN"]] } - } else { - res[["Action_Taken"]] <- res[["AEACN"]] } -} -# Outcome -if ("AEOUT" %in% toupper(names(res))) { - if (length(res[["AEOUT"]]) > 0) { - for (i in 1:length(res[["AEOUT"]])) { - res[["Outcome"]][i] <- switch(res[["AEOUT"]][i], - "RECOVERED/RESOLVED" = "Resolved", - "RECOVERING/RESOLVING" = "Resolving", - "RECOVERED/RESOLVED WITH SEQUELAE" = "Sequelae", - "NOT RECOVERED/NOT RESOLVED" = "Not Resolved", - tools::toTitleCase(tolower(res[["AEOUT"]][i])) - ) + # Outcome + if ("AEOUT" %in% toupper(names(res))) { + if (length(res[["AEOUT"]]) > 0) { + for (i in 1:length(res[["AEOUT"]])) { + res[["Outcome"]][i] <- switch(res[["AEOUT"]][i], + "RECOVERED/RESOLVED" = "Resolved", + "RECOVERING/RESOLVING" = "Resolving", + "RECOVERED/RESOLVED WITH SEQUELAE" = "Sequelae", + "NOT RECOVERED/NOT RESOLVED" = "Not Resolved", + tools::toTitleCase(tolower(res[["AEOUT"]][i])) + ) + } + } else { + res[["Outcome"]] <- res[["AEOUT"]] } - } else { - res[["Outcome"]] <- res[["AEOUT"]] } -} -# Total dose on day of AE onset -if ("AEDOSDUR" %in% toupper(names(res))) { - res[["ymd"]] <- substring(res[["AEDOSDUR"]], unlist(gregexpr("/P", res[["AEDOSDUR"]])) + 2) - - res[["Total_Dose_on_Day_of_AE_Onset"]] <- "" - - if (length(res[["AEDOSDUR"]]) > 0) { - for (i in 1:length(res[["AEDOSDUR"]])) { - if (unlist(gregexpr("Y", res[["ymd"]][i])) > 0) { - val_year <- substring(res[["ymd"]][i], 1, unlist(gregexpr("Y", res[["ymd"]][i])) - 1) - if (as.numeric(val_year) != 1) { - res[["Total_Dose_on_Day_of_AE_Onset"]][i] <- paste0(res[["Total_Dose_on_Day_of_AE_Onset"]][i], val_year, " years") - } else { - res[["Total_Dose_on_Day_of_AE_Onset"]][i] <- paste0(res[["Total_Dose_on_Day_of_AE_Onset"]][i], "1 year") + # Total dose on day of AE onset + if ("AEDOSDUR" %in% toupper(names(res))) { + res[["ymd"]] <- substring(res[["AEDOSDUR"]], unlist(gregexpr("/P", res[["AEDOSDUR"]])) + 2) + + res[["Total_Dose_on_Day_of_AE_Onset"]] <- "" + + if (length(res[["AEDOSDUR"]]) > 0) { + for (i in 1:length(res[["AEDOSDUR"]])) { + if (unlist(gregexpr("Y", res[["ymd"]][i])) > 0) { + val_year <- substring(res[["ymd"]][i], 1, unlist(gregexpr("Y", res[["ymd"]][i])) - 1) + if (as.numeric(val_year) != 1) { + res[["Total_Dose_on_Day_of_AE_Onset"]][i] <- paste0(res[["Total_Dose_on_Day_of_AE_Onset"]][i], val_year, " years") + } else { + res[["Total_Dose_on_Day_of_AE_Onset"]][i] <- paste0(res[["Total_Dose_on_Day_of_AE_Onset"]][i], "1 year") + } + + res[["ymd"]][i] <- substring(res[["ymd"]][i], unlist(gregexpr("Y", res[["ymd"]][i])) + 1) } + if (unlist(gregexpr("M", res[["ymd"]][i])) > 0) { + val_month <- substring(res[["ymd"]][i], 1, unlist(gregexpr("M", res[["ymd"]][i])) - 1) - res[["ymd"]][i] <- substring(res[["ymd"]][i], unlist(gregexpr("Y", res[["ymd"]][i])) + 1) - } - if (unlist(gregexpr("M", res[["ymd"]][i])) > 0) { - val_month <- substring(res[["ymd"]][i], 1, unlist(gregexpr("M", res[["ymd"]][i])) - 1) + if (as.numeric(val_month) != 1) { + res[["Total_Dose_on_Day_of_AE_Onset"]][i] <- paste0(res[["Total_Dose_on_Day_of_AE_Onset"]][i], " ", val_month, " months") + } else { + res[["Total_Dose_on_Day_of_AE_Onset"]][i] <- paste0(res[["Total_Dose_on_Day_of_AE_Onset"]][i], " 1 month") + } - if (as.numeric(val_month) != 1) { - res[["Total_Dose_on_Day_of_AE_Onset"]][i] <- paste0(res[["Total_Dose_on_Day_of_AE_Onset"]][i], " ", val_month, " months") - } else { - res[["Total_Dose_on_Day_of_AE_Onset"]][i] <- paste0(res[["Total_Dose_on_Day_of_AE_Onset"]][i], " 1 month") + res[["ymd"]][i] <- substring(res[["ymd"]][i], unlist(gregexpr("M", res[["ymd"]][i])) + 1) } - - res[["ymd"]][i] <- substring(res[["ymd"]][i], unlist(gregexpr("M", res[["ymd"]][i])) + 1) - } - if (unlist(gregexpr("D", res[["ymd"]][i])) > 0) { - val_day <- substring(res[["ymd"]][i], 1, unlist(gregexpr("D", res[["ymd"]][i])) - 1) - - if (as.numeric(val_day) != 1) { - res[["Total_Dose_on_Day_of_AE_Onset"]][i] <- paste0(res[["Total_Dose_on_Day_of_AE_Onset"]][i], " ", val_day, " days") - } else { - res[["Total_Dose_on_Day_of_AE_Onset"]][i] <- paste0(res[["Total_Dose_on_Day_of_AE_Onset"]][i], " 1 day") + if (unlist(gregexpr("D", res[["ymd"]][i])) > 0) { + val_day <- substring(res[["ymd"]][i], 1, unlist(gregexpr("D", res[["ymd"]][i])) - 1) + + if (as.numeric(val_day) != 1) { + res[["Total_Dose_on_Day_of_AE_Onset"]][i] <- paste0(res[["Total_Dose_on_Day_of_AE_Onset"]][i], " ", val_day, " days") + } else { + res[["Total_Dose_on_Day_of_AE_Onset"]][i] <- paste0(res[["Total_Dose_on_Day_of_AE_Onset"]][i], " 1 day") + } } } + } else { + res[["Total_Dose_on_Day_of_AE_Onset"]] <- res[["AEDOSDUR"]] } - } else { - res[["Total_Dose_on_Day_of_AE_Onset"]] <- res[["AEDOSDUR"]] + res <- res[, !(names(res) == "ymd"), drop = FALSE] } - res <- res[, !(names(res) == "ymd"), drop = FALSE] -} -# Customized variable will use label as column header in -# drill down listing on interactive forest plot -if (!display_unique_records) { - outdata[["ae_listing"]] <- res[, res_columns] -} else { - outdata[["ae_listing"]] <- unique(res[, res_columns]) -} + # Customized variable will use label as column header in + # drill down listing on interactive forest plot + if (!display_unique_records) { + outdata[["ae_listing"]] <- res[, res_columns] + } else { + outdata[["ae_listing"]] <- unique(res[, res_columns]) + } + + # Get all labels from the un-subset data + listing_label <- get_label(res) + listing_label <- gsub("_", " ", listing_label) + # Assign labels + outdata[["ae_listing"]] <- assign_label( + data = outdata[["ae_listing"]], + var = names(outdata[["ae_listing"]]), + label = listing_label[match(names(outdata[["ae_listing"]]), names(listing_label))] + ) -# Get all labels from the un-subset data -listing_label <- get_label(res) -listing_label <- gsub("_", " ", listing_label) -# Assign labels -outdata[["ae_listing"]] <- assign_label( - data = outdata[["ae_listing"]], - var = names(outdata[["ae_listing"]]), - label = listing_label[match(names(outdata[["ae_listing"]]), names(listing_label))] -) - -outdata + outdata } diff --git a/R/format_ae_forestly.R b/R/format_ae_forestly.R index 17157d9..dc1fff9 100644 --- a/R/format_ae_forestly.R +++ b/R/format_ae_forestly.R @@ -50,13 +50,13 @@ #' @export #' #' @examples -#' adsl <- forestly_adsl[1:100,] -#' adae <- forestly_adae[1:100,] +#' adsl <- forestly_adsl[1:100, ] +#' adae <- forestly_adae[1:100, ] #' meta_forestly( #' dataset_adsl = adsl, #' dataset_adae = adae #' ) |> -#' prepare_ae_forestly()|> +#' prepare_ae_forestly() |> #' format_ae_forestly() format_ae_forestly <- function( outdata, @@ -158,7 +158,7 @@ format_ae_forestly <- function( fig_prop_range <- round(range(tbl_prop, na.rm = TRUE) + c(-2, 2)) } else { if (prop_range[1] > range(tbl_prop, na.rm = TRUE)[1] | - prop_range[2] < range(tbl_prop, na.rm = TRUE)[2]) { + prop_range[2] < range(tbl_prop, na.rm = TRUE)[2]) { warning("There are data points outside the specified range for proportion.") } fig_prop_range <- prop_range @@ -204,7 +204,7 @@ format_ae_forestly <- function( fig_diff_range <- round(range(tbl_diff, na.rm = TRUE) + c(-2, 2)) } else { if (diff_range[1] > range(tbl_diff, na.rm = TRUE)[1] | - diff_range[2] < range(tbl_diff, na.rm = TRUE)[2]) { + diff_range[2] < range(tbl_diff, na.rm = TRUE)[2]) { warning("There are data points outside the specified range for difference.") } fig_diff_range <- diff_range @@ -369,14 +369,16 @@ format_ae_forestly <- function( ) # column hidden - columns <- lapply(columns, function (x) { + columns <- lapply(columns, function(x) { if (!"show" %in% names(x)) { x$show <- TRUE } return(x) }) - hidden_item <- names(columns)[(!names(columns) %in% "soc_name") & (sapply(columns, function(x) {return(!x$show)}))] + hidden_item <- names(columns)[(!names(columns) %in% "soc_name") & (sapply(columns, function(x) { + return(!x$show) + }))] # Create outdata outdata$tbl <- tbl diff --git a/R/prepare_ae_forestly.R b/R/prepare_ae_forestly.R index e3a1777..6b40968 100644 --- a/R/prepare_ae_forestly.R +++ b/R/prepare_ae_forestly.R @@ -29,8 +29,8 @@ #' @export #' #' @examples -#' adsl <- forestly_adsl[1:100,] -#' adae <- forestly_adae[1:100,] +#' adsl <- forestly_adsl[1:100, ] +#' adae <- forestly_adae[1:100, ] #' meta_forestly( #' dataset_adsl = adsl, #' dataset_adae = adae @@ -48,8 +48,6 @@ prepare_ae_forestly <- function( "AEREL", "AEACN", "AEOUT", "ADURN", "ADURU" ), ae_listing_unique = FALSE) { - - if (is.null(population)) { if (length(meta$population) == 1) { population <- meta$population[[1]]$name @@ -66,32 +64,32 @@ prepare_ae_forestly <- function( } } - if( is.null(parameter)){ + if (is.null(parameter)) { parameters <- names(meta$parameter) meta$parameter - }else{ + } else { parameters <- unlist(strsplit(parameter, ";")) } - for(i in seq_along(parameters)){ + for (i in seq_along(parameters)) { para <- meta$parameter[[parameters[i]]] - if(is.null(para$var)){ + if (is.null(para$var)) { para$var <- "AEDECOD" } - if(is.null(para$soc)){ + if (is.null(para$soc)) { para$soc <- "AEBODSYS" } - if(is.null(para$seq)){ + if (is.null(para$seq)) { para$seq <- sample(1e5:2e5, size = 1) } - if(is.null(para$term1)){ + if (is.null(para$term1)) { para$term1 <- "" } - if(is.null(para$term2)){ + if (is.null(para$term2)) { para$term2 <- "" } - if(is.null(para$summ_row)){ + if (is.null(para$summ_row)) { para$summ_row <- "" } meta$parameter[[parameters[i]]] <- para @@ -112,7 +110,7 @@ prepare_ae_forestly <- function( ae_listing <- data.frame() for (i in 1:length(res)) { - if (nrow(res[[i]]$ae_listing) > 0){ + if (nrow(res[[i]]$ae_listing) > 0) { res[[i]]$ae_listing$param <- res[[i]]$parameter ae_listing <- rbind(ae_listing, res[[i]]$ae_listing) } @@ -151,10 +149,12 @@ prepare_ae_forestly <- function( parameter_order <- factor(parameter_order, levels = parameters) # Display message if a specified-parameter is not included - if (any(!(parameters %in% unique(parameter_order)))){ - warning(paste0('There is no record for the parameter "', - parameters[!(parameters %in% unique(parameter_order))], - '" to display.')) + if (any(!(parameters %in% unique(parameter_order)))) { + warning(paste0( + 'There is no record for the parameter "', + parameters[!(parameters %in% unique(parameter_order))], + '" to display.' + )) } # Additional group information diff --git a/R/reactable2.R b/R/reactable2.R index a91b39e..dc03c38 100644 --- a/R/reactable2.R +++ b/R/reactable2.R @@ -111,16 +111,18 @@ reactable2 <- function( ) if (soc_toggle) { - on_click2 <- paste0("function control_column(hidden_columns) {", - " if (hidden_columns.includes('soc_name')) {", - " Reactable.setHiddenColumns('", element_id, "', prevColumns => { - return prevColumns.length === 0 ? ['soc_name']:[", hidden_item ,"]})", - " } else {", - " Reactable.setHiddenColumns('", element_id, "', prevColumns => { - return prevColumns.length === 0 ? [ ]: ['soc_name',", hidden_item, "]})", - " }", - "}", - "control_column(Reactable.getState('", element_id, "').hiddenColumns);") + on_click2 <- paste0( + "function control_column(hidden_columns) {", + " if (hidden_columns.includes('soc_name')) {", + " Reactable.setHiddenColumns('", element_id, "', prevColumns => { + return prevColumns.length === 0 ? ['soc_name']:[", hidden_item, "]})", + " } else {", + " Reactable.setHiddenColumns('", element_id, "', prevColumns => { + return prevColumns.length === 0 ? [ ]: ['soc_name',", hidden_item, "]})", + " }", + "}", + "control_column(Reactable.getState('", element_id, "').hiddenColumns);" + ) tbl <- htmltools::tagList( htmltools::tags$button( diff --git a/data-raw/forestly_adae.R b/data-raw/forestly_adae.R index c3b2efe..ceeed0a 100644 --- a/data-raw/forestly_adae.R +++ b/data-raw/forestly_adae.R @@ -9,19 +9,22 @@ adae <- r2rtf::r2rtf_adae # Derive AREL from existing AEREL -adae <- adae %>% filter(TRTA!="Xanomeline High Dose") %>% +adae <- adae %>% + filter(TRTA != "Xanomeline High Dose") %>% mutate(AREL = case_when( AEREL %in% c("PROBABLE", "POSSIBLE") ~ "RELATED", AEREL %in% c("NONE", "REMOTE", "") ~ "NOT RELATED", - TRUE ~ AEREL # Keep original AREL if none of the conditions are met + TRUE ~ AEREL # Keep original AREL if none of the conditions are met )) -freq <- adae %>% count(AREL, AEREL) %>% +freq <- adae %>% + count(AREL, AEREL) %>% arrange(desc(n)) print(freq) -freq2 <- forestly_adae %>% count(AREL, AEREL) %>% +freq2 <- forestly_adae %>% + count(AREL, AEREL) %>% arrange(desc(n)) print(freq2) @@ -39,17 +42,17 @@ adae$AEACN <- sample( for (i in seq_along(adae$AEACN)) { adae$action_taken[i] <- switch(adae$AEACN[i], - "DOSE NOT CHANGED" = "None", - "DRUG INTERRUPTED" = "Interrupted", - "DRUG WITHDRAWN" = "Discontinued", - "NOT APPLICABLE" = "N/A", - "UNKNOWN" = "Unknown", - "''" = "None", - tools::toTitleCase(tolower(adae$AEACN[i])) + "DOSE NOT CHANGED" = "None", + "DRUG INTERRUPTED" = "Interrupted", + "DRUG WITHDRAWN" = "Discontinued", + "NOT APPLICABLE" = "N/A", + "UNKNOWN" = "Unknown", + "''" = "None", + tools::toTitleCase(tolower(adae$AEACN[i])) ) } -#CHECKS +# CHECKS # freq <- adae %>% count(AEACN) %>% arrange(desc(n)) # print(freq) # diff --git a/man/format_ae_forestly.Rd b/man/format_ae_forestly.Rd index 2d44845..77850ba 100644 --- a/man/format_ae_forestly.Rd +++ b/man/format_ae_forestly.Rd @@ -75,12 +75,12 @@ An \code{outdata} object. Format outdata for interactive forest plot } \examples{ -adsl <- forestly_adsl[1:100,] -adae <- forestly_adae[1:100,] +adsl <- forestly_adsl[1:100, ] +adae <- forestly_adae[1:100, ] meta_forestly( dataset_adsl = adsl, dataset_adae = adae ) |> - prepare_ae_forestly()|> + prepare_ae_forestly() |> format_ae_forestly() } diff --git a/man/prepare_ae_forestly.Rd b/man/prepare_ae_forestly.Rd index aa286aa..b6bafc5 100644 --- a/man/prepare_ae_forestly.Rd +++ b/man/prepare_ae_forestly.Rd @@ -46,8 +46,8 @@ An \code{outdata} object. Prepare datasets for interactive forest plot } \examples{ -adsl <- forestly_adsl[1:100,] -adae <- forestly_adae[1:100,] +adsl <- forestly_adsl[1:100, ] +adae <- forestly_adae[1:100, ] meta_forestly( dataset_adsl = adsl, dataset_adae = adae diff --git a/vignettes/customize-ae-specific-columns.Rmd b/vignettes/customize-ae-specific-columns.Rmd index 703efbf..1f03c5c 100644 --- a/vignettes/customize-ae-specific-columns.Rmd +++ b/vignettes/customize-ae-specific-columns.Rmd @@ -43,31 +43,43 @@ Building interactive AE forest plots starts with constructing the metadata. The adsl <- forestly_adsl adae <- forestly_adae -adsl$TRTA <- factor(forestly_adsl$TRT01A, - levels = c("Xanomeline Low Dose", "Placebo"), - labels = c("Low Dose", "Placebo")) -adae$TRTA <- factor(forestly_adae$TRTA, - levels = c("Xanomeline Low Dose", "Placebo"), - labels = c("Low Dose", "Placebo")) +adsl$TRTA <- factor(forestly_adsl$TRT01A, + levels = c("Xanomeline Low Dose", "Placebo"), + labels = c("Low Dose", "Placebo") +) +adae$TRTA <- factor(forestly_adae$TRTA, + levels = c("Xanomeline Low Dose", "Placebo"), + labels = c("Low Dose", "Placebo") +) meta <- meta_adam(population = adsl, observation = adae) |> - define_plan(plan = plan(analysis = "ae_forestly", - population = "apat", - observation = "apat", - parameter = "any;drug-related")) |> + define_plan(plan = plan( + analysis = "ae_forestly", + population = "apat", + observation = "apat", + parameter = "any;drug-related" + )) |> define_analysis(name = "ae_forestly", label = "Interactive Forest Plot") |> - define_population(name = "apat", group = "TRTA", id = "USUBJID", - subset = SAFFL == "Y", label = "All Patient as Treated") |> - define_observation(name = "apat", group = "TRTA", - subset = SAFFL == "Y", label = "All Patient as Treated") |> - define_parameter(name = "any", - subset = NULL, - label = "Any AEs", - var = "AEDECOD", soc = "AEBODSYS") |> - define_parameter(name = "drug-related", - subset = toupper(AREL) == "RELATED", - label = "Drug-related AEs", - var = "AEDECOD", soc = "AEBODSYS") |> + define_population( + name = "apat", group = "TRTA", id = "USUBJID", + subset = SAFFL == "Y", label = "All Patient as Treated" + ) |> + define_observation( + name = "apat", group = "TRTA", + subset = SAFFL == "Y", label = "All Patient as Treated" + ) |> + define_parameter( + name = "any", + subset = NULL, + label = "Any AEs", + var = "AEDECOD", soc = "AEBODSYS" + ) |> + define_parameter( + name = "drug-related", + subset = toupper(AREL) == "RELATED", + label = "Drug-related AEs", + var = "AEDECOD", soc = "AEBODSYS" + ) |> meta_build() ``` @@ -92,4 +104,4 @@ meta |> prepare_ae_forestly() |> format_ae_forestly(display = c("n", "prop", "fig_prop", "fig_diff", "total")) |> ae_forestly() -``` \ No newline at end of file +``` diff --git a/vignettes/customize-color.Rmd b/vignettes/customize-color.Rmd index ba149a7..0311dd9 100644 --- a/vignettes/customize-color.Rmd +++ b/vignettes/customize-color.Rmd @@ -36,31 +36,43 @@ Building interactive AE forest plots starts with constructing the metadata. The adsl <- forestly_adsl adae <- forestly_adae -adsl$TRTA <- factor(forestly_adsl$TRT01A, - levels = c("Xanomeline Low Dose", "Placebo"), - labels = c("Low Dose", "Placebo")) -adae$TRTA <- factor(forestly_adae$TRTA, - levels = c("Xanomeline Low Dose", "Placebo"), - labels = c("Low Dose", "Placebo")) +adsl$TRTA <- factor(forestly_adsl$TRT01A, + levels = c("Xanomeline Low Dose", "Placebo"), + labels = c("Low Dose", "Placebo") +) +adae$TRTA <- factor(forestly_adae$TRTA, + levels = c("Xanomeline Low Dose", "Placebo"), + labels = c("Low Dose", "Placebo") +) meta <- meta_adam(population = adsl, observation = adae) |> - define_plan(plan = plan(analysis = "ae_forestly", - population = "apat", - observation = "apat", - parameter = "any;drug-related")) |> + define_plan(plan = plan( + analysis = "ae_forestly", + population = "apat", + observation = "apat", + parameter = "any;drug-related" + )) |> define_analysis(name = "ae_forestly", label = "Interactive Forest Plot") |> - define_population(name = "apat", group = "TRTA", id = "USUBJID", - subset = SAFFL == "Y", label = "All Patient as Treated") |> - define_observation(name = "apat", group = "TRTA", - subset = SAFFL == "Y", label = "All Patient as Treated") |> - define_parameter(name = "any", - subset = NULL, - label = "Any AEs", - var = "AEDECOD", soc = "AEBODSYS") |> - define_parameter(name = "drug-related", - subset = toupper(AREL) == "RELATED", - label = "Drug-related AEs", - var = "AEDECOD", soc = "AEBODSYS") |> + define_population( + name = "apat", group = "TRTA", id = "USUBJID", + subset = SAFFL == "Y", label = "All Patient as Treated" + ) |> + define_observation( + name = "apat", group = "TRTA", + subset = SAFFL == "Y", label = "All Patient as Treated" + ) |> + define_parameter( + name = "any", + subset = NULL, + label = "Any AEs", + var = "AEDECOD", soc = "AEBODSYS" + ) |> + define_parameter( + name = "drug-related", + subset = toupper(AREL) == "RELATED", + label = "Drug-related AEs", + var = "AEDECOD", soc = "AEBODSYS" + ) |> meta_build() ``` @@ -76,4 +88,4 @@ meta |> prepare_ae_forestly() |> format_ae_forestly(color = c("black", "grey60", "grey40")) |> ae_forestly() -``` \ No newline at end of file +``` diff --git a/vignettes/customize-diff-label.Rmd b/vignettes/customize-diff-label.Rmd index 455ba1e..30918ef 100644 --- a/vignettes/customize-diff-label.Rmd +++ b/vignettes/customize-diff-label.Rmd @@ -36,31 +36,43 @@ Building interactive AE forest plots starts with constructing the metadata. The adsl <- forestly_adsl adae <- forestly_adae -adsl$TRTA <- factor(forestly_adsl$TRT01A, - levels = c("Xanomeline Low Dose", "Placebo"), - labels = c("Low Dose", "Placebo")) -adae$TRTA <- factor(forestly_adae$TRTA, - levels = c("Xanomeline Low Dose", "Placebo"), - labels = c("Low Dose", "Placebo")) +adsl$TRTA <- factor(forestly_adsl$TRT01A, + levels = c("Xanomeline Low Dose", "Placebo"), + labels = c("Low Dose", "Placebo") +) +adae$TRTA <- factor(forestly_adae$TRTA, + levels = c("Xanomeline Low Dose", "Placebo"), + labels = c("Low Dose", "Placebo") +) meta <- meta_adam(population = adsl, observation = adae) |> - define_plan(plan = plan(analysis = "ae_forestly", - population = "apat", - observation = "apat", - parameter = "any;drug-related")) |> + define_plan(plan = plan( + analysis = "ae_forestly", + population = "apat", + observation = "apat", + parameter = "any;drug-related" + )) |> define_analysis(name = "ae_forestly", label = "Interactive Forest Plot") |> - define_population(name = "apat", group = "TRTA", id = "USUBJID", - subset = SAFFL == "Y", label = "All Patient as Treated") |> - define_observation(name = "apat", group = "TRTA", - subset = SAFFL == "Y", label = "All Patient as Treated") |> - define_parameter(name = "any", - subset = NULL, - label = "Any AEs", - var = "AEDECOD", soc = "AEBODSYS") |> - define_parameter(name = "drug-related", - subset = toupper(AREL) == "RELATED", - label = "Drug-related AEs", - var = "AEDECOD", soc = "AEBODSYS") |> + define_population( + name = "apat", group = "TRTA", id = "USUBJID", + subset = SAFFL == "Y", label = "All Patient as Treated" + ) |> + define_observation( + name = "apat", group = "TRTA", + subset = SAFFL == "Y", label = "All Patient as Treated" + ) |> + define_parameter( + name = "any", + subset = NULL, + label = "Any AEs", + var = "AEDECOD", soc = "AEBODSYS" + ) |> + define_parameter( + name = "drug-related", + subset = toupper(AREL) == "RELATED", + label = "Drug-related AEs", + var = "AEDECOD", soc = "AEBODSYS" + ) |> meta_build() ``` @@ -74,6 +86,6 @@ In the example below, we show how to change the legend text. We encourage users ```{r} meta |> prepare_ae_forestly() |> - format_ae_forestly(diff_label = "New Drug <- Favor -> SoC",) |> + format_ae_forestly(diff_label = "New Drug <- Favor -> SoC", ) |> ae_forestly() -``` \ No newline at end of file +``` diff --git a/vignettes/customize-digits.Rmd b/vignettes/customize-digits.Rmd index 5a748c2..c14353e 100644 --- a/vignettes/customize-digits.Rmd +++ b/vignettes/customize-digits.Rmd @@ -36,31 +36,43 @@ Building interactive AE forest plots starts with constructing the metadata. The adsl <- forestly_adsl adae <- forestly_adae -adsl$TRTA <- factor(forestly_adsl$TRT01A, - levels = c("Xanomeline Low Dose", "Placebo"), - labels = c("Low Dose", "Placebo")) -adae$TRTA <- factor(forestly_adae$TRTA, - levels = c("Xanomeline Low Dose", "Placebo"), - labels = c("Low Dose", "Placebo")) +adsl$TRTA <- factor(forestly_adsl$TRT01A, + levels = c("Xanomeline Low Dose", "Placebo"), + labels = c("Low Dose", "Placebo") +) +adae$TRTA <- factor(forestly_adae$TRTA, + levels = c("Xanomeline Low Dose", "Placebo"), + labels = c("Low Dose", "Placebo") +) meta <- meta_adam(population = adsl, observation = adae) |> - define_plan(plan = plan(analysis = "ae_forestly", - population = "apat", - observation = "apat", - parameter = "any;drug-related")) |> + define_plan(plan = plan( + analysis = "ae_forestly", + population = "apat", + observation = "apat", + parameter = "any;drug-related" + )) |> define_analysis(name = "ae_forestly", label = "Interactive Forest Plot") |> - define_population(name = "apat", group = "TRTA", id = "USUBJID", - subset = SAFFL == "Y", label = "All Patient as Treated") |> - define_observation(name = "apat", group = "TRTA", - subset = SAFFL == "Y", label = "All Patient as Treated") |> - define_parameter(name = "any", - subset = NULL, - label = "Any AEs", - var = "AEDECOD", soc = "AEBODSYS") |> - define_parameter(name = "drug-related", - subset = toupper(AREL) == "RELATED", - label = "Drug-related AEs", - var = "AEDECOD", soc = "AEBODSYS") |> + define_population( + name = "apat", group = "TRTA", id = "USUBJID", + subset = SAFFL == "Y", label = "All Patient as Treated" + ) |> + define_observation( + name = "apat", group = "TRTA", + subset = SAFFL == "Y", label = "All Patient as Treated" + ) |> + define_parameter( + name = "any", + subset = NULL, + label = "Any AEs", + var = "AEDECOD", soc = "AEBODSYS" + ) |> + define_parameter( + name = "drug-related", + subset = toupper(AREL) == "RELATED", + label = "Drug-related AEs", + var = "AEDECOD", soc = "AEBODSYS" + ) |> meta_build() ``` @@ -74,4 +86,4 @@ meta |> prepare_ae_forestly() |> format_ae_forestly(digits = 2) |> ae_forestly() -``` \ No newline at end of file +``` diff --git a/vignettes/customize-listing-columns.Rmd b/vignettes/customize-listing-columns.Rmd index 4df780d..1786f49 100644 --- a/vignettes/customize-listing-columns.Rmd +++ b/vignettes/customize-listing-columns.Rmd @@ -38,31 +38,43 @@ Building interactive AE forest plots starts with constructing the metadata. The adsl <- forestly_adsl adae <- forestly_adae -adsl$TRTA <- factor(forestly_adsl$TRT01A, - levels = c("Xanomeline Low Dose", "Placebo"), - labels = c("Low Dose", "Placebo")) -adae$TRTA <- factor(forestly_adae$TRTA, - levels = c("Xanomeline Low Dose", "Placebo"), - labels = c("Low Dose", "Placebo")) +adsl$TRTA <- factor(forestly_adsl$TRT01A, + levels = c("Xanomeline Low Dose", "Placebo"), + labels = c("Low Dose", "Placebo") +) +adae$TRTA <- factor(forestly_adae$TRTA, + levels = c("Xanomeline Low Dose", "Placebo"), + labels = c("Low Dose", "Placebo") +) meta <- meta_adam(population = adsl, observation = adae) |> - define_plan(plan = plan(analysis = "ae_forestly", - population = "apat", - observation = "apat", - parameter = "any;drug-related")) |> + define_plan(plan = plan( + analysis = "ae_forestly", + population = "apat", + observation = "apat", + parameter = "any;drug-related" + )) |> define_analysis(name = "ae_forestly", label = "Interactive Forest Plot") |> - define_population(name = "apat", group = "TRTA", id = "USUBJID", - subset = SAFFL == "Y", label = "All Patient as Treated") |> - define_observation(name = "apat", group = "TRTA", - subset = SAFFL == "Y", label = "All Patient as Treated") |> - define_parameter(name = "any", - subset = NULL, - label = "Any AEs", - var = "AEDECOD", soc = "AEBODSYS") |> - define_parameter(name = "drug-related", - subset = toupper(AREL) == "RELATED", - label = "Drug-related AEs", - var = "AEDECOD", soc = "AEBODSYS") |> + define_population( + name = "apat", group = "TRTA", id = "USUBJID", + subset = SAFFL == "Y", label = "All Patient as Treated" + ) |> + define_observation( + name = "apat", group = "TRTA", + subset = SAFFL == "Y", label = "All Patient as Treated" + ) |> + define_parameter( + name = "any", + subset = NULL, + label = "Any AEs", + var = "AEDECOD", soc = "AEBODSYS" + ) |> + define_parameter( + name = "drug-related", + subset = toupper(AREL) == "RELATED", + label = "Drug-related AEs", + var = "AEDECOD", soc = "AEBODSYS" + ) |> meta_build() ``` @@ -77,4 +89,4 @@ meta |> prepare_ae_forestly(ae_listing_display = c("USUBJID", "SITEID", "SEX", "RACE", "AGE")) |> format_ae_forestly() |> ae_forestly() -``` \ No newline at end of file +``` diff --git a/vignettes/customize-width.Rmd b/vignettes/customize-width.Rmd index 4e7de68..a39b333 100644 --- a/vignettes/customize-width.Rmd +++ b/vignettes/customize-width.Rmd @@ -36,31 +36,43 @@ Building interactive AE forest plots starts with constructing the metadata. The adsl <- forestly_adsl adae <- forestly_adae -adsl$TRTA <- factor(forestly_adsl$TRT01A, - levels = c("Xanomeline Low Dose", "Placebo"), - labels = c("Low Dose", "Placebo")) -adae$TRTA <- factor(forestly_adae$TRTA, - levels = c("Xanomeline Low Dose", "Placebo"), - labels = c("Low Dose", "Placebo")) +adsl$TRTA <- factor(forestly_adsl$TRT01A, + levels = c("Xanomeline Low Dose", "Placebo"), + labels = c("Low Dose", "Placebo") +) +adae$TRTA <- factor(forestly_adae$TRTA, + levels = c("Xanomeline Low Dose", "Placebo"), + labels = c("Low Dose", "Placebo") +) meta <- meta_adam(population = adsl, observation = adae) |> - define_plan(plan = plan(analysis = "ae_forestly", - population = "apat", - observation = "apat", - parameter = "any;drug-related")) |> + define_plan(plan = plan( + analysis = "ae_forestly", + population = "apat", + observation = "apat", + parameter = "any;drug-related" + )) |> define_analysis(name = "ae_forestly", label = "Interactive Forest Plot") |> - define_population(name = "apat", group = "TRTA", id = "USUBJID", - subset = SAFFL == "Y", label = "All Patient as Treated") |> - define_observation(name = "apat", group = "TRTA", - subset = SAFFL == "Y", label = "All Patient as Treated") |> - define_parameter(name = "any", - subset = NULL, - label = "Any AEs", - var = "AEDECOD", soc = "AEBODSYS") |> - define_parameter(name = "drug-related", - subset = toupper(AREL) == "RELATED", - label = "Drug-related AEs", - var = "AEDECOD", soc = "AEBODSYS") |> + define_population( + name = "apat", group = "TRTA", id = "USUBJID", + subset = SAFFL == "Y", label = "All Patient as Treated" + ) |> + define_observation( + name = "apat", group = "TRTA", + subset = SAFFL == "Y", label = "All Patient as Treated" + ) |> + define_parameter( + name = "any", + subset = NULL, + label = "Any AEs", + var = "AEDECOD", soc = "AEBODSYS" + ) |> + define_parameter( + name = "drug-related", + subset = toupper(AREL) == "RELATED", + label = "Drug-related AEs", + var = "AEDECOD", soc = "AEBODSYS" + ) |> meta_build() ``` @@ -81,14 +93,16 @@ In the example below, we modify the column widths to better suit the display. Us ```{r} meta |> prepare_ae_forestly() |> - format_ae_forestly(width_term = 5, # width of the column of AE PT term - # widths of the column of subject with AE counts - width_n = 2, - # widths of the column of AE proportions - width_prop = 2, - # widths of plotting the AE proportions and differences - width_fig = 150, - # vertical space between legend and the table - footer_space = 100) |> + format_ae_forestly( + width_term = 5, # width of the column of AE PT term + # widths of the column of subject with AE counts + width_n = 2, + # widths of the column of AE proportions + width_prop = 2, + # widths of plotting the AE proportions and differences + width_fig = 150, + # vertical space between legend and the table + footer_space = 100 + ) |> ae_forestly() -``` \ No newline at end of file +``` diff --git a/vignettes/customize-xlimit.Rmd b/vignettes/customize-xlimit.Rmd index d767b0a..4af5a6f 100644 --- a/vignettes/customize-xlimit.Rmd +++ b/vignettes/customize-xlimit.Rmd @@ -36,31 +36,43 @@ Building interactive AE forest plots starts with constructing the metadata. The adsl <- forestly_adsl adae <- forestly_adae -adsl$TRTA <- factor(forestly_adsl$TRT01A, - levels = c("Xanomeline Low Dose", "Placebo"), - labels = c("Low Dose", "Placebo")) -adae$TRTA <- factor(forestly_adae$TRTA, - levels = c("Xanomeline Low Dose", "Placebo"), - labels = c("Low Dose", "Placebo")) +adsl$TRTA <- factor(forestly_adsl$TRT01A, + levels = c("Xanomeline Low Dose", "Placebo"), + labels = c("Low Dose", "Placebo") +) +adae$TRTA <- factor(forestly_adae$TRTA, + levels = c("Xanomeline Low Dose", "Placebo"), + labels = c("Low Dose", "Placebo") +) meta <- meta_adam(population = adsl, observation = adae) |> - define_plan(plan = plan(analysis = "ae_forestly", - population = "apat", - observation = "apat", - parameter = "any;drug-related")) |> + define_plan(plan = plan( + analysis = "ae_forestly", + population = "apat", + observation = "apat", + parameter = "any;drug-related" + )) |> define_analysis(name = "ae_forestly", label = "Interactive Forest Plot") |> - define_population(name = "apat", group = "TRTA", id = "USUBJID", - subset = SAFFL == "Y", label = "All Patient as Treated") |> - define_observation(name = "apat", group = "TRTA", - subset = SAFFL == "Y", label = "All Patient as Treated") |> - define_parameter(name = "any", - subset = NULL, - label = "Any AEs", - var = "AEDECOD", soc = "AEBODSYS") |> - define_parameter(name = "drug-related", - subset = toupper(AREL) == "RELATED", - label = "Drug-related AEs", - var = "AEDECOD", soc = "AEBODSYS") |> + define_population( + name = "apat", group = "TRTA", id = "USUBJID", + subset = SAFFL == "Y", label = "All Patient as Treated" + ) |> + define_observation( + name = "apat", group = "TRTA", + subset = SAFFL == "Y", label = "All Patient as Treated" + ) |> + define_parameter( + name = "any", + subset = NULL, + label = "Any AEs", + var = "AEDECOD", soc = "AEBODSYS" + ) |> + define_parameter( + name = "drug-related", + subset = toupper(AREL) == "RELATED", + label = "Drug-related AEs", + var = "AEDECOD", soc = "AEBODSYS" + ) |> meta_build() ``` @@ -78,4 +90,4 @@ meta |> prepare_ae_forestly() |> format_ae_forestly(prop_range = c(-0.5, 30), diff_range = c(-10, 35)) |> ae_forestly() -``` \ No newline at end of file +``` diff --git a/vignettes/forestly.Rmd b/vignettes/forestly.Rmd index d9087b8..8172b0c 100644 --- a/vignettes/forestly.Rmd +++ b/vignettes/forestly.Rmd @@ -48,12 +48,14 @@ library(forestly) adsl <- forestly_adsl adae <- forestly_adae -adsl$TRTA <- factor(forestly_adsl$TRT01A, - levels = c("Xanomeline Low Dose", "Placebo"), - labels = c("Low Dose", "Placebo")) -adae$TRTA <- factor(forestly_adae$TRTA, - levels = c("Xanomeline Low Dose", "Placebo"), - labels = c("Low Dose", "Placebo")) +adsl$TRTA <- factor(forestly_adsl$TRT01A, + levels = c("Xanomeline Low Dose", "Placebo"), + labels = c("Low Dose", "Placebo") +) +adae$TRTA <- factor(forestly_adae$TRTA, + levels = c("Xanomeline Low Dose", "Placebo"), + labels = c("Low Dose", "Placebo") +) ``` ## Step 2: build the metadata @@ -74,59 +76,73 @@ Without loss of generality, our plan is to generate the following four AE-specif However, users are allowed to add more AE-specific tables as needed. For the above 4 AE specific tables, we take the APaT for both observation and observation. ```{r} meta <- meta |> - define_plan(plan = plan(analysis = "ae_forestly", - population = "apat", - observation = "apat", - parameter = "any;drug-related;serious;drug-related-serious")) + define_plan(plan = plan( + analysis = "ae_forestly", + population = "apat", + observation = "apat", + parameter = "any;drug-related;serious;drug-related-serious" + )) ``` Following the definition of the analysis plan, we further specify the details of `analysis = "ae_forestly"` by providing its label for display. ```{r} meta <- meta |> - define_analysis(name = "ae_forestly", label = "Interactive Forest Plot") + define_analysis(name = "ae_forestly", label = "Interactive Forest Plot") ``` We then define the related population (`population = "apat"`) and observation (`observation = "apat"`) by specifying their grouping variable (`group = ...`), subject ID (`id = ...`), population flag (`subset = ...`) and label (`label = ...`). If users wish to use different population flags, grouping variables, or labels, they can make changes as needed. ```{r} meta <- meta |> - define_population(name = "apat", group = "TRTA", id = "USUBJID", - subset = SAFFL == "Y", label = "All Patient as Treated") |> - define_observation(name = "apat", group = "TRTA", - subset = SAFFL == "Y", label = "All Patient as Treated") + define_population( + name = "apat", group = "TRTA", id = "USUBJID", + subset = SAFFL == "Y", label = "All Patient as Treated" + ) |> + define_observation( + name = "apat", group = "TRTA", + subset = SAFFL == "Y", label = "All Patient as Treated" + ) ``` Next, we specify the details of `parameter = "any;drug-related;serious;drug-related-serious"`. For any AEs (`"any"`), their is no filter applied. ```{r} meta <- meta |> - define_parameter(name = "any", - subset = NULL, - label = "Any AEs", - var = "AEDECOD", soc = "AEBODSYS") + define_parameter( + name = "any", + subset = NULL, + label = "Any AEs", + var = "AEDECOD", soc = "AEBODSYS" + ) ``` For drug related AEs (`"drug-related"`), its filter is `AEREL %in% c("PROBABLE", "POSSIBLE")`. ```{r} meta <- meta |> - define_parameter(name = "drug-related", - subset = toupper(AREL) == "RELATED", - label = "Drug-related AEs", - var = "AEDECOD", soc = "AEBODSYS") + define_parameter( + name = "drug-related", + subset = toupper(AREL) == "RELATED", + label = "Drug-related AEs", + var = "AEDECOD", soc = "AEBODSYS" + ) ``` Similarly, we define serious AE and drug related serious AEs. ```{r} meta <- meta |> - define_parameter(name = "serious", - subset = AESER == "Y", - label = "Serious AEs", - var = "AEDECOD", soc = "AEBODSYS") |> - define_parameter(name = "drug-related-serious", - subset = AESER == "Y" & AEREL %in% c("PROBABLE", "POSSIBLE"), - label = "Drug-related serious AEs", - var = "AEDECOD", soc = "AEBODSYS") + define_parameter( + name = "serious", + subset = AESER == "Y", + label = "Serious AEs", + var = "AEDECOD", soc = "AEBODSYS" + ) |> + define_parameter( + name = "drug-related-serious", + subset = AESER == "Y" & AEREL %in% c("PROBABLE", "POSSIBLE"), + label = "Drug-related serious AEs", + var = "AEDECOD", soc = "AEBODSYS" + ) ``` Finally, we build the metadata by running the `meta_build()` function. ```{r} -meta <- meta |> meta_build() +meta <- meta |> meta_build() ``` ## Step 3: generate the interative AE forest plot