From 1129f26bcab43900099cca179b007ce7be8871ec Mon Sep 17 00:00:00 2001 From: LittleBeannie Date: Wed, 2 Jul 2025 12:04:22 -0400 Subject: [PATCH 1/3] add a new function --- R/react_base_char_new.R | 127 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 R/react_base_char_new.R diff --git a/R/react_base_char_new.R b/R/react_base_char_new.R new file mode 100644 index 0000000..70ba58a --- /dev/null +++ b/R/react_base_char_new.R @@ -0,0 +1,127 @@ +# Copyright (c) 2024 Merck & Co., Inc., Rahway, NJ, USA and its affiliates. +# All rights reserved. +# +# This file is part of the metalite.sl program. +# +# metalite.sl is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +#' Display interactive baseline characteristic tables with AE subgroup analysis +#' +#' @param metadata_sl A metadata created by metalite, +#' which builds the baseline characteristic table +#' @param population A character value of population term name. +#' The term name is used as key to link information. +#' @param display_total Display total column or not. +#' @param sl_parameter A character value of parameter term name for +#' the baseline characteristic table. +#' The term name is used as key to link information. +#' @param width A numeric value of width of the table in pixels. +#' +#' @return An reactable combing both baseline characteristic table +#' and AE subgroup specific tables. +#' +#' @export +#' +#' @examples +#' if (interactive()) { +#' react_base_char_new(metadata_sl = meta_sl_example(), +#' population = "apat", +#' observation = "wk12", +#' display_total = TRUE, +#' sl_parameter = "age;gender;race", +#' width = 1200) +#' } +react_base_char_new <- function( + metadata_sl, + population = "apat", + observation = "wk12", + display_total = TRUE, + sl_parameter = "age;gender;race", + width = 1200) { + # ----------------------------------------- # + # total setting # + # ----------------------------------------- # + + if (display_total == TRUE) { + display_sl <- c("n", "prop", "total") + } else { + display_sl <- c("n", "prop") + } + + # ----------------------------------------- # + # prepare the baseline char table numbers # + # ----------------------------------------- # + x_sl <- metadata_sl |> + prepare_sl_summary( + population = population, + analysis = metadata_sl$plan$analysis, + parameter = sl_parameter + ) |> + format_base_char(display_col = display_sl, digits_prop = 2) + + tbl_sl <- x_sl$tbl + tbl_sl$var_label[tbl_sl$name == "Participants in population"] <- "Participants in population" + + # ----------------------------------------- # + # build interactive baseline char table # + # ----------------------------------------- # + # Define Column + col_defs <- list() + for (sl_name in names(tbl_sl)) { + if (startsWith(sl_name, "n_")) { + col_defs[[sl_name]] <- reactable::colDef(name = "n") + } else if (startsWith(sl_name, "p_")) { + col_defs[[sl_name]] <- reactable::colDef(name = "(%)") + } else { + col_defs[[sl_name]] <- reactable::colDef(name = " ") + } + } + + # Define Column Group + col_group_defs <- list() + for (i in 1:length(x_sl$group_label)) { + group <- levels(x_sl$group_label)[i] + col_group_defs <- append( + col_group_defs, + list(reactable::colGroup( + name = group, + columns = c(paste0("n_", i), paste0("p_", i)) + )) + ) + } + if (display_total == TRUE) { + col_group_defs <- append( + col_group_defs, + list(reactable::colGroup( + name = "Total", + columns = c("n_9999", "p_9999") + )) + ) + } + + tbl_sl_shared <- crosstalk::SharedData$new(tbl_sl) + shiny::fluidRow( + shiny::column( + 4, + crosstalk::filter_checkbox("var_label", "Select your baseline characteristics to view", tbl_sl_shared, ~var_label) + ), + shiny::column( + 8, + reactable::reactable(tbl_sl_shared, groupBy = "var_label", + width = width, columns = col_defs, + columnGroups = col_group_defs) + ) + ) + +} From 496c117641a9e9f0b7aa39aaef62ad26ae4abc5d Mon Sep 17 00:00:00 2001 From: LittleBeannie Date: Wed, 2 Jul 2025 12:04:37 -0400 Subject: [PATCH 2/3] update Rd and namespace --- NAMESPACE | 1 + man/react_base_char_new.Rd | 60 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 man/react_base_char_new.Rd diff --git a/NAMESPACE b/NAMESPACE index d6d425f..624d2ab 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -20,6 +20,7 @@ export(prepare_exp_duration) export(prepare_sl_summary) export(prepare_trt_compliance) export(react_base_char) +export(react_base_char_new) export(react_disposition) export(rtf_base_char) export(rtf_base_char_subgroup) diff --git a/man/react_base_char_new.Rd b/man/react_base_char_new.Rd new file mode 100644 index 0000000..4c4dbdb --- /dev/null +++ b/man/react_base_char_new.Rd @@ -0,0 +1,60 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/react_base_char_new.R +\name{react_base_char_new} +\alias{react_base_char_new} +\title{Display interactive baseline characteristic tables with AE subgroup analysis} +\usage{ +react_base_char_new( + metadata_sl, + population = "apat", + observation = "wk12", + display_total = TRUE, + sl_parameter = "age;gender;race", + width = 1200 +) +} +\arguments{ +\item{metadata_sl}{A metadata created by metalite, +which builds the baseline characteristic table} + +\item{population}{A character value of population term name. +The term name is used as key to link information.} + +\item{observation}{A character value of observation term name. +The term name is used as key to link information.} + +\item{display_total}{Display total column or not.} + +\item{sl_parameter}{A character value of parameter term name for +the baseline characteristic table. +The term name is used as key to link information.} + +\item{width}{A numeric value of width of the table in pixels.} + +\item{metadata_ae}{A metadata created by metalite, +which builds the AE subgroup specific table} + +\item{ae_subgroup}{A vector of strubf to specify the subgroups +in the AE subgroup specific table.} + +\item{ae_specific}{A string specifying the AE specific category.} +} +\value{ +An reactable combing both baseline characteristic table +and AE subgroup specific tables. +} +\description{ +Display interactive baseline characteristic tables with AE subgroup analysis +} +\examples{ +if (interactive()) { + react_base_char_new( + metadata_sl = meta_sl_example(), + population = "apat", + observation = "wk12", + display_total = TRUE, + sl_parameter = "age;gender;race", + width = 1200 + ) +} +} From 2a8f578ae5ec7f776442676f1ebdd32d80c28781 Mon Sep 17 00:00:00 2001 From: LittleBeannie Date: Wed, 2 Jul 2025 12:05:59 -0400 Subject: [PATCH 3/3] update documentation --- DESCRIPTION | 1 + man/react_base_char_new.Rd | 25 ++++++------------------- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index fa4cd76..08d013e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -21,6 +21,7 @@ Description: Analyzes subject-level data in clinical trials using the 'metalite' Depends: R (>= 4.1.0) License: GPL (>= 3) Imports: + crosstalk, glue, metalite, metalite.ae, diff --git a/man/react_base_char_new.Rd b/man/react_base_char_new.Rd index 4c4dbdb..579dce7 100644 --- a/man/react_base_char_new.Rd +++ b/man/react_base_char_new.Rd @@ -20,9 +20,6 @@ which builds the baseline characteristic table} \item{population}{A character value of population term name. The term name is used as key to link information.} -\item{observation}{A character value of observation term name. -The term name is used as key to link information.} - \item{display_total}{Display total column or not.} \item{sl_parameter}{A character value of parameter term name for @@ -30,14 +27,6 @@ the baseline characteristic table. The term name is used as key to link information.} \item{width}{A numeric value of width of the table in pixels.} - -\item{metadata_ae}{A metadata created by metalite, -which builds the AE subgroup specific table} - -\item{ae_subgroup}{A vector of strubf to specify the subgroups -in the AE subgroup specific table.} - -\item{ae_specific}{A string specifying the AE specific category.} } \value{ An reactable combing both baseline characteristic table @@ -48,13 +37,11 @@ Display interactive baseline characteristic tables with AE subgroup analysis } \examples{ if (interactive()) { - react_base_char_new( - metadata_sl = meta_sl_example(), - population = "apat", - observation = "wk12", - display_total = TRUE, - sl_parameter = "age;gender;race", - width = 1200 - ) +react_base_char_new(metadata_sl = meta_sl_example(), + population = "apat", + observation = "wk12", + display_total = TRUE, + sl_parameter = "age;gender;race", + width = 1200) } }