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 f3ef362..02432fe 100644 --- a/R/ae_listing.R +++ b/R/ae_listing.R @@ -208,9 +208,9 @@ format_ae_listing <- function(outdata, display_unique_records = FALSE) { } attr(res[["Participant_ID"]], "label") <- NULL - res[["Gender"]] <- titlecase(res[["SEX"]]) + res[["Gender"]] <- tools::toTitleCase(res[["SEX"]]) - res[["Race"]] <- titlecase(res[["RACE"]]) + res[["Race"]] <- tools::toTitleCase(tolower(res[["RACE"]])) res[["Age"]] <- res[["AGE"]] @@ -220,10 +220,9 @@ format_ae_listing <- function(outdata, display_unique_records = FALSE) { # Onset epoch if ("EPOCH" %in% toupper(names(res))) { - res[["Onset_Epoch"]] <- titlecase(res[["EPOCH"]]) + 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"]] @@ -239,7 +238,7 @@ format_ae_listing <- function(outdata, display_unique_records = FALSE) { # Duration if ("ADURN" %in% toupper(names(res)) & "ADURU" %in% toupper(names(res))) { res[["Duration"]] <- paste(ifelse(is.na(res[["ADURN"]]), "", as.character(res[["ADURN"]])), - titlecase(res[["ADURU"]]), + tools::toTitleCase(tolower(res[["ADURU"]])), sep = " " ) # AE duration with unit @@ -275,7 +274,7 @@ format_ae_listing <- function(outdata, display_unique_records = FALSE) { # AE related if ("AEREL" %in% toupper(names(res))) { res[["Related"]] <- ifelse(res[["AEREL"]] == "RELATED", "Y", ifelse( - toupper(res[["AEREL"]]) == "NOT RELATED", "N", titlecase(res[["AEREL"]]) + toupper(res[["AEREL"]]) == "NOT RELATED", "N", tools::toTitleCase(tolower(res[["AEREL"]])) )) } @@ -290,7 +289,7 @@ format_ae_listing <- function(outdata, display_unique_records = FALSE) { "DOSE INCREASED" = "Increased", "NOT APPLICABLE" = "N/A", "UNKNOWN" = "Unknown", - titlecase(res[["AEACN"]][i]) + tools::toTitleCase(tolower(res[["AEACN"]][i])) ) } } else { @@ -307,7 +306,7 @@ format_ae_listing <- function(outdata, display_unique_records = FALSE) { "RECOVERING/RESOLVING" = "Resolving", "RECOVERED/RESOLVED WITH SEQUELAE" = "Sequelae", "NOT RECOVERED/NOT RESOLVED" = "Not Resolved", - titlecase(res[["AEOUT"]][i]) + tools::toTitleCase(tolower(res[["AEOUT"]][i])) ) } } else { 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