From 767f217c2ff6ef0c38d0bd6874005c4651d5b6fa Mon Sep 17 00:00:00 2001 From: "benjamin.wang@merck.com" Date: Thu, 9 May 2024 14:36:57 -0400 Subject: [PATCH 01/12] change function name of base_char --- NAMESPACE | 2 +- R/format_base_char.R | 4 ++-- R/prepare_base_char.R | 4 ++-- R/react_base_char.R | 2 +- R/rtf_base_char.R | 4 ++-- README.md | 4 ++-- man/format_base_char.Rd | 4 ++-- man/prepare_base_char.Rd | 10 +++++----- man/rtf_base_char.Rd | 4 ++-- .../test-independent-testing-format_base_char.R | 2 +- .../test-independent-testing-prepare_base_char.R | 4 ++-- .../testthat/test-independent-testing-rtf_base_char.R | 2 +- vignettes/metalite-sl.Rmd | 2 +- 13 files changed, 24 insertions(+), 24 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 3d74578..ab5f5f6 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,6 +4,6 @@ export(collect_baseline) export(defmt_pct) export(format_base_char) export(meta_sl_example) -export(prepare_base_char) +export(prepare_sl_summary) export(react_base_char) export(rtf_base_char) diff --git a/R/format_base_char.R b/R/format_base_char.R index 01015eb..43ec018 100644 --- a/R/format_base_char.R +++ b/R/format_base_char.R @@ -18,7 +18,7 @@ #' Prepare data for baseline characteristic table #' -#' @param outdata A metadata object created by [prepare_base_char()]. +#' @param outdata A metadata object created by [prepare_sl_summary()]. #' @param display_col Column wants to display on the table. #' The term could be selected from `c("n", "prop", "total")`. #' @param digits_prop Number of digits for proportion columns. @@ -34,7 +34,7 @@ #' meta <- meta_sl_example() #' #' meta |> -#' prepare_base_char(parameter = "age;gender") |> +#' prepare_sl_summary(parameter = "age;gender") |> #' format_base_char() format_base_char <- function( outdata, diff --git a/R/prepare_base_char.R b/R/prepare_base_char.R index 1edb882..a12621f 100644 --- a/R/prepare_base_char.R +++ b/R/prepare_base_char.R @@ -34,8 +34,8 @@ #' #' @examples #' meta <- meta_sl_example() -#' meta |> prepare_base_char() -prepare_base_char <- function( +#' meta |> prepare_sl_summary() +prepare_sl_summary <- function( meta, population = "apat", observation = "wk12", diff --git a/R/react_base_char.R b/R/react_base_char.R index ad89630..c912b71 100644 --- a/R/react_base_char.R +++ b/R/react_base_char.R @@ -78,7 +78,7 @@ react_base_char <- function( # prepare the baseline char table numbers # # ----------------------------------------- # x_sl <- metadata_sl |> - prepare_base_char( + prepare_sl_summary( population = population, observation = population, analysis = "base_char", diff --git a/R/rtf_base_char.R b/R/rtf_base_char.R index e9c0df3..85eb0d9 100644 --- a/R/rtf_base_char.R +++ b/R/rtf_base_char.R @@ -18,7 +18,7 @@ #' Baseline characteristic table #' -#' @param outdata An `outdata` object created by [prepare_base_char()]. +#' @param outdata An `outdata` object created by [prepare_sl_summary()]. #' @param source A character value of the data source. #' @inheritParams r2rtf::rtf_page #' @inheritParams r2rtf::rtf_body @@ -35,7 +35,7 @@ #' meta <- meta_sl_example() #' #' meta |> -#' prepare_base_char( +#' prepare_sl_summary( #' population = "apat", #' observation = "apat", #' parameter = "age;gender" diff --git a/README.md b/README.md index 709f811..4143017 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ inputs and outputs. The general workflow is: 1. Define metadata information using metalite. -2. `prepare_base_char()` prepares datasets for summary of baseline characteristics. +2. `prepare_sl_summary()` prepares datasets for summary of baseline characteristics. 3. `format_base_char()` formats output layout. 4. `rtf_base_char()` creates TLFs. @@ -26,7 +26,7 @@ Here is a quick example library("metalite.sl") meta_sl_example() |> - prepare_base_char( + prepare_sl_summary( population = "apat", observation = "apat", parameter = "age;gender" diff --git a/man/format_base_char.Rd b/man/format_base_char.Rd index 7e0ff3b..929dc5a 100644 --- a/man/format_base_char.Rd +++ b/man/format_base_char.Rd @@ -12,7 +12,7 @@ format_base_char( ) } \arguments{ -\item{outdata}{A metadata object created by \code{\link[=prepare_base_char]{prepare_base_char()}}.} +\item{outdata}{A metadata object created by \code{\link[=prepare_sl_summary]{prepare_sl_summary()}}.} \item{display_col}{Column wants to display on the table. The term could be selected from \code{c("n", "prop", "total")}.} @@ -33,6 +33,6 @@ Prepare data for baseline characteristic table meta <- meta_sl_example() meta |> - prepare_base_char(parameter = "age;gender") |> + prepare_sl_summary(parameter = "age;gender") |> format_base_char() } diff --git a/man/prepare_base_char.Rd b/man/prepare_base_char.Rd index cacde4c..235d5c2 100644 --- a/man/prepare_base_char.Rd +++ b/man/prepare_base_char.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/prepare_base_char.R -\name{prepare_base_char} -\alias{prepare_base_char} +% Please edit documentation in R/prepare_sl_summary.R +\name{prepare_sl_summary} +\alias{prepare_sl_summary} \title{Prepare data for baseline characteristic table} \usage{ -prepare_base_char( +prepare_sl_summary( meta, population = "apat", observation = "wk12", @@ -35,5 +35,5 @@ Prepare data for baseline characteristic table } \examples{ meta <- meta_sl_example() -meta |> prepare_base_char() +meta |> prepare_sl_summary() } diff --git a/man/rtf_base_char.Rd b/man/rtf_base_char.Rd index 3403c84..809eadc 100644 --- a/man/rtf_base_char.Rd +++ b/man/rtf_base_char.Rd @@ -17,7 +17,7 @@ rtf_base_char( ) } \arguments{ -\item{outdata}{An \code{outdata} object created by \code{\link[=prepare_base_char]{prepare_base_char()}}.} +\item{outdata}{An \code{outdata} object created by \code{\link[=prepare_sl_summary]{prepare_sl_summary()}}.} \item{source}{A character value of the data source.} @@ -48,7 +48,7 @@ Baseline characteristic table meta <- meta_sl_example() meta |> - prepare_base_char( + prepare_sl_summary( population = "apat", observation = "apat", parameter = "age;gender" diff --git a/tests/testthat/test-independent-testing-format_base_char.R b/tests/testthat/test-independent-testing-format_base_char.R index 7135832..cd0d16c 100644 --- a/tests/testthat/test-independent-testing-format_base_char.R +++ b/tests/testthat/test-independent-testing-format_base_char.R @@ -61,7 +61,7 @@ test_meta_base_char <- meta_adam( title = "Participant Baseline Characteristics by Treatment Group", var_name = c("AGEGR1", "AGE", "RACE", "SEX") ) |> - prepare_base_char( + prepare_sl_summary( population = "apat", observation = "apat", analysis = "base_char", diff --git a/tests/testthat/test-independent-testing-prepare_base_char.R b/tests/testthat/test-independent-testing-prepare_base_char.R index 270df7c..81b8c6d 100644 --- a/tests/testthat/test-independent-testing-prepare_base_char.R +++ b/tests/testthat/test-independent-testing-prepare_base_char.R @@ -65,7 +65,7 @@ meta_test <- meta_adam( ) # Prepare test data by the tested function -test_meta_base_char <- prepare_base_char( +test_meta_base_char <- prepare_sl_summary( meta_test, population = "apat", observation = "apat", @@ -344,6 +344,6 @@ test_that("Parameter matching", { expect_equal(test_meta_base_char$parameter, "age;agen;gender;race") }) -test_that("Output from prepare_base_char is a list", { +test_that("Output from prepare_sl_summary is a list", { expect_true("outdata" %in% class(test_meta_base_char)) }) diff --git a/tests/testthat/test-independent-testing-rtf_base_char.R b/tests/testthat/test-independent-testing-rtf_base_char.R index 49b1e3f..38215a7 100644 --- a/tests/testthat/test-independent-testing-rtf_base_char.R +++ b/tests/testthat/test-independent-testing-rtf_base_char.R @@ -1,7 +1,7 @@ # library(metalite) # # meta <- meta_sl_example() -# outdata <- prepare_base_char(meta, +# outdata <- prepare_sl_summary(meta, # population = "apat", # observation = "apat", # parameter = "age;gender" diff --git a/vignettes/metalite-sl.Rmd b/vignettes/metalite-sl.Rmd index fb11288..9b738e5 100644 --- a/vignettes/metalite-sl.Rmd +++ b/vignettes/metalite-sl.Rmd @@ -75,7 +75,7 @@ meta <- meta_adam( ```{r} outdata <- meta |> - prepare_base_char( + prepare_sl_summary( population = "apat", observation = "wk12", analysis = "base_char", From 9def987ef3e68677a4271112e5281b4fb6132fba Mon Sep 17 00:00:00 2001 From: niup0 Date: Wed, 15 May 2024 16:34:27 -0400 Subject: [PATCH 02/12] Add new plan for trt_compliance Use all participants randomized population for base_char --- R/meta_sl_example.R | 50 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/R/meta_sl_example.R b/R/meta_sl_example.R index 0dc9f75..b2839bc 100644 --- a/R/meta_sl_example.R +++ b/R/meta_sl_example.R @@ -34,27 +34,46 @@ meta_sl_example <- function() { levels = c("Placebo", "Xanomeline Low Dose", "Xanomeline High Dose"), labels = c("Placebo", "Low Dose", "High Dose") ) - + + plan <- metalite::plan( + analysis = "base_char", population = "apr", + observation = "apr", parameter = "age;gender;race" + ) |> + metalite::add_plan( + analysis = "trt_compliance", population = "apat", + observation = "apat", parameter = "comp8;comp16;comp24" + ) + meta <- metalite::meta_adam( population = adsl, observation = adsl ) |> - metalite::define_plan(plan = metalite::plan( - analysis = "base_char", population = "apat", - observation = "apat", parameter = "age;gender;race" - )) |> + metalite::define_plan(plan) |> metalite::define_population( name = "apat", group = "TRTA", subset = quote(SAFFL == "Y"), var = c("USUBJID", "TRTA", "SAFFL", "AGEGR1", "SEX", "RACE") ) |> + metalite::define_population( + name = "apr", + group = "TRTA", + subset = quote(ITTFL == "Y"), + label = "All Participants Randomized" + ) |> metalite::define_observation( name = "apat", group = "TRTA", subset = quote(SAFFL == "Y"), var = c("USUBJID", "TRTA", "SAFFL", "AGEGR1", "SEX", "RACE") ) |> + metalite::define_observation( + name = "apr", + group = "TRTA", + subset = quote(ITTFL == "Y"), + label = "All Participants Randomized" + ) |> + # For Baseline Characteristic metalite::define_parameter( name = "age", var = "AGE", @@ -77,5 +96,26 @@ meta_sl_example <- function() { label = "baseline characteristic table", var_name = c("AGEGR1", "SEX") ) |> + # For compliance + metalite::define_parameter( + name = "comp8", + var = "COMP8FL", + label = "Compliance (Week 8)", + ) |> + metalite::define_parameter( + name = "comp16", + var = "COMP16FL", + label = "Compliance (Week 16)", + ) |> + metalite::define_parameter( + name = "comp24", + var = "COMP24FL", + label = "Compliance (Week 24)", + ) |> + metalite::define_analysis( + name = "trt_compliance", + title = "Summary of Treatment Compliance", + label = "treatment compliance table" + ) |> metalite::meta_build() } From 1f7f2b604ff27e8fd95ea13b737c930fdca2e021 Mon Sep 17 00:00:00 2001 From: niup0 Date: Fri, 17 May 2024 15:41:38 -0400 Subject: [PATCH 03/12] Add 'prepare_trt_compliance' function --- NAMESPACE | 1 + R/prepare_trt_compliance.R | 53 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 R/prepare_trt_compliance.R diff --git a/NAMESPACE b/NAMESPACE index ab5f5f6..95034d7 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,5 +5,6 @@ export(defmt_pct) export(format_base_char) export(meta_sl_example) export(prepare_sl_summary) +export(prepare_trt_compliance) export(react_base_char) export(rtf_base_char) diff --git a/R/prepare_trt_compliance.R b/R/prepare_trt_compliance.R new file mode 100644 index 0000000..bdc1223 --- /dev/null +++ b/R/prepare_trt_compliance.R @@ -0,0 +1,53 @@ +# 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 . + +#' Prepare data for baseline characteristic table +#' +#' @param meta A metadata object created by metalite. +#' @param population A character value of population term name. +#' The term name is used as key to link information. +# @param observation A character value of observation term name. +# The term name is used as key to link information. +#' @param analysis A character value of analysis term name. +#' The term name is used as key to link information. +#' @param parameter A character value of parameter term name. +#' The term name is used as key to link information. +# @param display_total A logic value of displaying the total group. +#' +#' @return A list of analysis raw datasets. +#' +#' @export +#' +#' @examples +#' meta <- meta_sl_example() +#' meta |> prepare_trt_compliance() +prepare_trt_compliance <- function(meta, + analysis = "trt_compliance", + population = meta$plan[meta$plan$analysis==analysis,]$population, + parameter = paste(meta$plan[meta$plan$analysis==analysis,]$parameter, collapse = ";") #, display_total = TRUE + ) { + return( + prepare_sl_summary(meta, + analysis = analysis, + population = population, + observation = population, + parameter = parameter #, display_total = display_total + ) + ) + +} From 8d360d0db1b0204db08078a4f373d2a42c7696d3 Mon Sep 17 00:00:00 2001 From: niup0 Date: Fri, 17 May 2024 15:45:04 -0400 Subject: [PATCH 04/12] update manual --- R/prepare_trt_compliance.R | 2 +- ...are_base_char.Rd => prepare_sl_summary.Rd} | 2 +- man/prepare_trt_compliance.Rd | 36 +++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) rename man/{prepare_base_char.Rd => prepare_sl_summary.Rd} (94%) create mode 100644 man/prepare_trt_compliance.Rd diff --git a/R/prepare_trt_compliance.R b/R/prepare_trt_compliance.R index bdc1223..f5dd822 100644 --- a/R/prepare_trt_compliance.R +++ b/R/prepare_trt_compliance.R @@ -16,7 +16,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -#' Prepare data for baseline characteristic table +#' Prepare data for treatment compliance table #' #' @param meta A metadata object created by metalite. #' @param population A character value of population term name. diff --git a/man/prepare_base_char.Rd b/man/prepare_sl_summary.Rd similarity index 94% rename from man/prepare_base_char.Rd rename to man/prepare_sl_summary.Rd index 235d5c2..0b01707 100644 --- a/man/prepare_base_char.Rd +++ b/man/prepare_sl_summary.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/prepare_sl_summary.R +% Please edit documentation in R/prepare_base_char.R \name{prepare_sl_summary} \alias{prepare_sl_summary} \title{Prepare data for baseline characteristic table} diff --git a/man/prepare_trt_compliance.Rd b/man/prepare_trt_compliance.Rd new file mode 100644 index 0000000..89d1ff8 --- /dev/null +++ b/man/prepare_trt_compliance.Rd @@ -0,0 +1,36 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/prepare_trt_compliance.R +\name{prepare_trt_compliance} +\alias{prepare_trt_compliance} +\title{Prepare data for treatment compliance table} +\usage{ +prepare_trt_compliance( + meta, + analysis = "trt_compliance", + population = meta$plan[meta$plan$analysis == analysis, ]$population, + parameter = paste(meta$plan[meta$plan$analysis == analysis, ]$parameter, collapse = + ";") +) +} +\arguments{ +\item{meta}{A metadata object created by metalite.} + +\item{analysis}{A character value of analysis term name. +The term name is used as key to link information.} + +\item{population}{A character value of population term name. +The term name is used as key to link information.} + +\item{parameter}{A character value of parameter term name. +The term name is used as key to link information.} +} +\value{ +A list of analysis raw datasets. +} +\description{ +Prepare data for treatment compliance table +} +\examples{ +meta <- meta_sl_example() +meta |> prepare_trt_compliance() +} From 8fca7d16dc471b26156d2373370f3f6a325ebc47 Mon Sep 17 00:00:00 2001 From: "Wang, Benjamin" Date: Wed, 5 Jun 2024 23:11:47 -0400 Subject: [PATCH 05/12] update tables --- R/prepare_base_char.R | 93 ++++++------------------------ R/prepare_disposition.R | 51 +++++++++++++++++ R/prepare_sl_summary.R | 111 ++++++++++++++++++++++++++++++++++++ R/prepare_trt_compliance.R | 5 +- vignettes/metalite-sl.Rmd | 113 +++++++++++++++++++++++++++++++++---- 5 files changed, 282 insertions(+), 91 deletions(-) create mode 100644 R/prepare_disposition.R create mode 100644 R/prepare_sl_summary.R diff --git a/R/prepare_base_char.R b/R/prepare_base_char.R index a12621f..5ce600f 100644 --- a/R/prepare_base_char.R +++ b/R/prepare_base_char.R @@ -16,17 +16,18 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -#' Prepare data for baseline characteristic table +#' Prepare data for treatment compliance table #' #' @param meta A metadata object created by metalite. #' @param population A character value of population term name. #' The term name is used as key to link information. -#' @param observation A character value of observation term name. -#' The term name is used as key to link information. +# @param observation A character value of observation term name. +# The term name is used as key to link information. #' @param analysis A character value of analysis term name. #' The term name is used as key to link information. #' @param parameter A character value of parameter term name. #' The term name is used as key to link information. +# @param display_total A logic value of displaying the total group. #' #' @return A list of analysis raw datasets. #' @@ -34,79 +35,17 @@ #' #' @examples #' meta <- meta_sl_example() -#' meta |> prepare_sl_summary() -prepare_sl_summary <- function( - meta, - population = "apat", - observation = "wk12", - analysis = "base_char", - parameter = paste(names(meta$parameter), collapse = ";")) { - parameters <- unlist(strsplit(parameter, ";")) - - # obtain variables - pop_var <- metalite::collect_adam_mapping(meta, population)$var - obs_var <- metalite::collect_adam_mapping(meta, observation)$var - par_var <- metalite::collect_adam_mapping(meta, parameter)$var - - pop_group <- metalite::collect_adam_mapping(meta, population)$group - obs_group <- metalite::collect_adam_mapping(meta, observation)$group - - pop_id <- metalite::collect_adam_mapping(meta, population)$id - obs_id <- metalite::collect_adam_mapping(meta, observation)$id - - # obtain data - pop <- metalite::collect_population_record(meta, population, var = pop_var) - - # obtain group names - group <- unique(pop[[pop_group]]) - - # count the number of subjects in each arms - n_pop <- metalite::n_subject(id = pop[[pop_id]], group = pop[[pop_group]]) - names(n_pop) <- do.call( - c, - lapply( - factor(names(n_pop), levels = levels(pop[[pop_group]])) |> as.numeric(), - function(x) { - paste0("n_", x) - } +#' meta |> prepare_base_char() +prepare_base_char <- function(meta, + analysis = "base_char", + population = meta$plan[meta$plan$analysis==analysis,]$population, + parameter = paste(meta$plan[meta$plan$analysis==analysis,]$parameter, collapse = ";") +) { + return( + prepare_sl_summary(meta, + analysis = analysis, + population = population, + parameter = parameter ) ) - n_pop$n_9999 <- sum(n_pop[1, ]) - n_pop$name <- "Participants in population" - n_pop <- n_pop[, c(length(group) + 2, 1:(length(group) + 1))] - n_pop$var_label <- "-----" - - # Get the baseline characteristics variables in adsl - # char_var <- collect_adam_mapping(meta, analysis)$var_name - char_var <- do.call(c, lapply(parameters, function(x) { - metalite::collect_adam_mapping(meta, x)$var - })) - - # Get the baseline characteristics counts - char_n <- lapply(parameters, function(x) { - collect_baseline(meta, population, x)[[2]] - }) - - # Get the baseline characteristics propositions - char_prop <- lapply(parameters, function(x) { - collect_baseline(meta, population, x)[[3]] - }) - - # Get the variable date type - var_type <- lapply(parameters, function(x) { - collect_baseline(meta, population, x)[[4]] - }) - - ans <- metalite::outdata( - meta, population, observation, parameter, - n = n_pop, - order = NULL, group = pop_group, reference_group = NULL, - char_n = char_n, - char_var = char_var, - char_prop = char_prop, - var_type = var_type, - group_label = unique(pop[[pop_group]]) - ) - - return(ans) -} +} \ No newline at end of file diff --git a/R/prepare_disposition.R b/R/prepare_disposition.R new file mode 100644 index 0000000..a9e9437 --- /dev/null +++ b/R/prepare_disposition.R @@ -0,0 +1,51 @@ +# 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 . + +#' Prepare data for treatment compliance table +#' +#' @param meta A metadata object created by metalite. +#' @param population A character value of population term name. +#' The term name is used as key to link information. +# @param observation A character value of observation term name. +# The term name is used as key to link information. +#' @param analysis A character value of analysis term name. +#' The term name is used as key to link information. +#' @param parameter A character value of parameter term name. +#' The term name is used as key to link information. +# @param display_total A logic value of displaying the total group. +#' +#' @return A list of analysis raw datasets. +#' +#' @export +#' +#' @examples +#' meta <- meta_sl_example() +#' meta |> prepare_base_char() +prepare_disposition <- function(meta, + analysis = "disp", + population = meta$plan[meta$plan$analysis==analysis,]$population, + parameter = paste(meta$plan[meta$plan$analysis==analysis,]$parameter, collapse = ";") +) { + return( + prepare_sl_summary(meta, + analysis = analysis, + population = population, + parameter = parameter + ) + ) +} \ No newline at end of file diff --git a/R/prepare_sl_summary.R b/R/prepare_sl_summary.R new file mode 100644 index 0000000..b52b4f0 --- /dev/null +++ b/R/prepare_sl_summary.R @@ -0,0 +1,111 @@ +# 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 . + +#' Prepare data for baseline characteristic table +#' +#' @param meta A metadata object created by metalite. +#' @param population A character value of population term name. +#' The term name is used as key to link information. +#' @param observation A character value of observation term name. +#' The term name is used as key to link information. +#' @param analysis A character value of analysis term name. +#' The term name is used as key to link information. +#' @param parameter A character value of parameter term name. +#' The term name is used as key to link information. +#' +#' @return A list of analysis raw datasets. +#' +#' @export +#' +#' @examples +#' meta <- meta_sl_example() +#' meta |> prepare_sl_summary() +prepare_sl_summary <- function( + meta, + population, + analysis, + parameter = paste(names(meta$parameter), collapse = ";")) { + parameters <- unlist(strsplit(parameter, ";")) + observation <- meta$plan[meta$plan$analysis==analysis,]$observation + # obtain variables + pop_var <- metalite::collect_adam_mapping(meta, population)$var + obs_var <- metalite::collect_adam_mapping(meta, observation)$var + par_var <- metalite::collect_adam_mapping(meta, parameter)$var + + pop_group <- metalite::collect_adam_mapping(meta, population)$group + obs_group <- metalite::collect_adam_mapping(meta, observation)$group + + pop_id <- metalite::collect_adam_mapping(meta, population)$id + obs_id <- metalite::collect_adam_mapping(meta, observation)$id + + # obtain data + pop <- metalite::collect_population_record(meta, population, var = pop_var) + + # obtain group names + group <- unique(pop[[pop_group]]) + + # count the number of subjects in each arms + n_pop <- metalite::n_subject(id = pop[[pop_id]], group = pop[[pop_group]]) + names(n_pop) <- do.call( + c, + lapply( + factor(names(n_pop), levels = levels(pop[[pop_group]])) |> as.numeric(), + function(x) { + paste0("n_", x) + } + ) + ) + n_pop$n_9999 <- sum(n_pop[1, ]) + n_pop$name <- "Participants in population" + n_pop <- n_pop[, c(length(group) + 2, 1:(length(group) + 1))] + n_pop$var_label <- "-----" + + # Get the baseline characteristics variables in adsl + # char_var <- collect_adam_mapping(meta, analysis)$var_name + char_var <- do.call(c, lapply(parameters, function(x) { + metalite::collect_adam_mapping(meta, x)$var + })) + + # Get the baseline characteristics counts + char_n <- lapply(parameters, function(x) { + collect_baseline(meta, population, x)[[2]] + }) + + # Get the baseline characteristics propositions + char_prop <- lapply(parameters, function(x) { + collect_baseline(meta, population, x)[[3]] + }) + + # Get the variable date type + var_type <- lapply(parameters, function(x) { + collect_baseline(meta, population, x)[[4]] + }) + + ans <- metalite::outdata( + meta, population, observation, parameter, + n = n_pop, + order = NULL, group = pop_group, reference_group = NULL, + char_n = char_n, + char_var = char_var, + char_prop = char_prop, + var_type = var_type, + group_label = unique(pop[[pop_group]]) + ) + + return(ans) +} diff --git a/R/prepare_trt_compliance.R b/R/prepare_trt_compliance.R index f5dd822..7bb0b66 100644 --- a/R/prepare_trt_compliance.R +++ b/R/prepare_trt_compliance.R @@ -39,14 +39,13 @@ prepare_trt_compliance <- function(meta, analysis = "trt_compliance", population = meta$plan[meta$plan$analysis==analysis,]$population, - parameter = paste(meta$plan[meta$plan$analysis==analysis,]$parameter, collapse = ";") #, display_total = TRUE + parameter = paste(meta$plan[meta$plan$analysis==analysis,]$parameter, collapse = ";") ) { return( prepare_sl_summary(meta, analysis = analysis, population = population, - observation = population, - parameter = parameter #, display_total = display_total + parameter = parameter ) ) diff --git a/vignettes/metalite-sl.Rmd b/vignettes/metalite-sl.Rmd index 9b738e5..89eeec7 100644 --- a/vignettes/metalite-sl.Rmd +++ b/vignettes/metalite-sl.Rmd @@ -27,19 +27,42 @@ adsl$TRTA <- factor(adsl$TRTA, labels = c("Placebo", "Low Dose", "High Dose") ) +# Create a variable EOSSTT indicating the end of end of study status +adsl$EOSSTT <- sample(x = c("Participants Ongoing", "Discontinued"), + size = length(adsl$USUBJID), + prob = c(0.8, 0.2), replace = TRUE) +# Create a variable EOTSTT1 indicating the end of treatment status part 1 +adsl$EOTSTT1 <- sample(x = c("Completed", "Discontinued"), + size = length(adsl$USUBJID), + prob = c(0.85, 0.15), replace = TRUE) +``` + +```{r} +plan <- plan( + analysis = "base_char", population = "apat", + observation = "apat", parameter = "age;gender;race" + ) |> + add_plan( + analysis = "disp", population = "apat", + observation = "apat", parameter = "disposition;medical-disposition" + ) |> + add_plan( + analysis = "trt_compliance", population = "apat", + observation = "apat", parameter = "comp8;comp16;comp24" + ) +``` + +```{r} meta <- meta_adam( population = adsl, observation = adsl ) |> - define_plan(plan = plan( - analysis = "base_char", population = "apat", - observation = "apat", parameter = "age;gender;race" - )) |> + define_plan(plan = plan) |> define_population( name = "apat", group = "TRTA", subset = quote(SAFFL == "Y"), - var = c("USUBJID", "TRTA", "SAFFL", "AGEGR1", "SEX", "RACE") + var = c("USUBJID", "TRTA", "SAFFL", "AGEGR1", "SEX", "RACE", "EOSSTT", "EOTSTT1", "COMP8FL", "COMP16FL", "COMP24FL") ) |> define_observation( name = "apat", @@ -63,11 +86,46 @@ meta <- meta_adam( var = "RACE", label = "Race" ) |> + define_parameter( + name = "disposition", + var = "EOSSTT", + label = "Trial Disposition" + ) |> + define_parameter( + name = "medical-disposition", + var = "EOTSTT1", + label = "Participant Study Medication Disposition" + ) |> + metalite::define_parameter( + name = "comp8", + var = "COMP8FL", + label = "Compliance (Week 8)", + ) |> + metalite::define_parameter( + name = "comp16", + var = "COMP16FL", + label = "Compliance (Week 16)", + ) |> + metalite::define_parameter( + name = "comp24", + var = "COMP24FL", + label = "Compliance (Week 24)", + ) |> define_analysis( name = "base_char", title = "Participant Baseline Characteristics by Treatment Group", label = "baseline characteristic table" ) |> + define_analysis( + name = "trt_compliance", + title = "Summary of Treatment Compliance", + label = "treatment compliance table" + ) |> + define_analysis( + name = "disp", + title = "Disposition of Participant", + label = "disposition table" + ) |> meta_build() ``` @@ -75,10 +133,7 @@ meta <- meta_adam( ```{r} outdata <- meta |> - prepare_sl_summary( - population = "apat", - observation = "wk12", - analysis = "base_char", + prepare_base_char( parameter = "age;gender;race" ) @@ -109,7 +164,43 @@ outdata$tbl ```{r} outdata |> rtf_base_char( source = "Source: [CDISCpilot: adam-adsl]", - path_outdata = file.path(tempdir(), "base0char111.rtf"), - path_outtable = tempfile(fileext = ".Rdata") + path_outdata = tempfile(fileext = ".Rdata"), + path_outtable = "base_char.rtf" ) ``` + +# Create Treatment Compliance Table + +```{r} +outdata <- meta |> + prepare_trt_compliance() +outdata +``` + +```{r} +outdata |> + format_base_char(display_col = c("n", "prop"), digits_prop = 3) |> + rtf_base_char( + source = "Source: [CDISCpilot: adam-adsl]", + path_outdata = tempfile(fileext = ".Rdata"), + path_outtable = tempfile(fileext = ".rtf") +) +``` + +# Create Treatment Compliance Table + +```{r} +outdata <- meta |> + prepare_disposition() +outdata +``` + +```{r} +outdata |> + format_base_char() |> + rtf_base_char( + source = "Source: [CDISCpilot: adam-adsl]", + path_outdata = tempfile(fileext = ".Rdata"), + path_outtable = tempfile(fileext = ".rtf") +) +``` \ No newline at end of file From 566c9ad157105837399cd9885d37f341e3a9a1bb Mon Sep 17 00:00:00 2001 From: "Wang, Benjamin" Date: Wed, 12 Jun 2024 14:58:41 -0400 Subject: [PATCH 06/12] update name --- NAMESPACE | 6 +++ R/format_base_char.R | 37 +++++++++++++++++- R/meta_sl_example.R | 75 ++++++++++++++++++++---------------- R/react_base_char.R | 1 - R/rtf_base_char.R | 43 +++++++++++++++++++++ man/format_base_char.Rd | 2 +- man/format_disposition.Rd | 38 ++++++++++++++++++ man/format_trt_compliance.Rd | 38 ++++++++++++++++++ man/prepare_base_char.Rd | 36 +++++++++++++++++ man/prepare_disposition.Rd | 36 +++++++++++++++++ man/prepare_sl_summary.Rd | 13 +++---- man/rtf_disposition.Rd | 39 +++++++++++++++++++ man/rtf_trt_compliance.Rd | 39 +++++++++++++++++++ vignettes/metalite-sl.Rmd | 15 +++----- 14 files changed, 364 insertions(+), 54 deletions(-) create mode 100644 man/format_disposition.Rd create mode 100644 man/format_trt_compliance.Rd create mode 100644 man/prepare_base_char.Rd create mode 100644 man/prepare_disposition.Rd create mode 100644 man/rtf_disposition.Rd create mode 100644 man/rtf_trt_compliance.Rd diff --git a/NAMESPACE b/NAMESPACE index 95034d7..221744d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -3,8 +3,14 @@ export(collect_baseline) export(defmt_pct) export(format_base_char) +export(format_disposition) +export(format_trt_compliance) export(meta_sl_example) +export(prepare_base_char) +export(prepare_disposition) export(prepare_sl_summary) export(prepare_trt_compliance) export(react_base_char) export(rtf_base_char) +export(rtf_disposition) +export(rtf_trt_compliance) diff --git a/R/format_base_char.R b/R/format_base_char.R index 43ec018..240a5c9 100644 --- a/R/format_base_char.R +++ b/R/format_base_char.R @@ -34,7 +34,7 @@ #' meta <- meta_sl_example() #' #' meta |> -#' prepare_sl_summary(parameter = "age;gender") |> +#' prepare_base_char(parameter = "age;gender") |> #' format_base_char() format_base_char <- function( outdata, @@ -119,3 +119,38 @@ format_base_char <- function( return(outdata) } + +#' Format Treatment Compliance Analysis +#' +#' @inheritParams format_base_char +#' +#' @return A list of analysis raw datasets. +#' +#' @export +#' +#' @examples +#' meta <- meta_sl_example() +#' +#' meta |> +#' prepare_trt_compliance(parameter = "comp8;comp16") |> +#' format_trt_compliance() +format_trt_compliance <- format_base_char + + +#' Format Disposition Analysis +#' +#' @inheritParams format_base_char +#' +#' @return A list of analysis raw datasets. +#' +#' @export +#' +#' @examples +#' meta <- meta_sl_example() +#' +#' meta |> +#' prepare_disposition(parameter = "disposition;medical-disposition") |> +#' format_disposition() +format_disposition <- format_base_char + + diff --git a/R/meta_sl_example.R b/R/meta_sl_example.R index b2839bc..1587873 100644 --- a/R/meta_sl_example.R +++ b/R/meta_sl_example.R @@ -35,13 +35,26 @@ meta_sl_example <- function() { labels = c("Placebo", "Low Dose", "High Dose") ) + # Create a variable EOSSTT indicating the end of end of study status + adsl$EOSSTT <- sample(x = c("Participants Ongoing", "Discontinued"), + size = length(adsl$USUBJID), + prob = c(0.8, 0.2), replace = TRUE) + # Create a variable EOTSTT1 indicating the end of treatment status part 1 + adsl$EOTSTT1 <- sample(x = c("Completed", "Discontinued"), + size = length(adsl$USUBJID), + prob = c(0.85, 0.15), replace = TRUE) + plan <- metalite::plan( - analysis = "base_char", population = "apr", - observation = "apr", parameter = "age;gender;race" + analysis = "base_char", population = "apat", + observation = "apat", parameter = "age;gender;race" ) |> metalite::add_plan( analysis = "trt_compliance", population = "apat", observation = "apat", parameter = "comp8;comp16;comp24" + ) |> + add_plan( + analysis = "disp", population = "apat", + observation = "apat", parameter = "disposition;medical-disposition" ) meta <- metalite::meta_adam( @@ -49,54 +62,38 @@ meta_sl_example <- function() { observation = adsl ) |> metalite::define_plan(plan) |> - metalite::define_population( - name = "apat", - group = "TRTA", - subset = quote(SAFFL == "Y"), - var = c("USUBJID", "TRTA", "SAFFL", "AGEGR1", "SEX", "RACE") - ) |> - metalite::define_population( - name = "apr", - group = "TRTA", - subset = quote(ITTFL == "Y"), - label = "All Participants Randomized" - ) |> - metalite::define_observation( + define_population( name = "apat", group = "TRTA", subset = quote(SAFFL == "Y"), - var = c("USUBJID", "TRTA", "SAFFL", "AGEGR1", "SEX", "RACE") - ) |> - metalite::define_observation( - name = "apr", - group = "TRTA", - subset = quote(ITTFL == "Y"), - label = "All Participants Randomized" + var = c("USUBJID", "TRTA", "SAFFL", "AGEGR1", "SEX", "RACE", "EOSSTT", "EOTSTT1", "COMP8FL", "COMP16FL", "COMP24FL") ) |> - # For Baseline Characteristic - metalite::define_parameter( + define_parameter( name = "age", var = "AGE", label = "Age (years)", vargroup = "AGEGR1" ) |> - metalite::define_parameter( + define_parameter( name = "gender", var = "SEX", label = "Gender" ) |> - metalite::define_parameter( + define_parameter( name = "race", var = "RACE", label = "Race" ) |> - metalite::define_analysis( - name = "base_char", - title = "Participant Baseline Characteristics by Treatment Group", - label = "baseline characteristic table", - var_name = c("AGEGR1", "SEX") + define_parameter( + name = "disposition", + var = "EOSSTT", + label = "Trial Disposition" + ) |> + define_parameter( + name = "medical-disposition", + var = "EOTSTT1", + label = "Participant Study Medication Disposition" ) |> - # For compliance metalite::define_parameter( name = "comp8", var = "COMP8FL", @@ -112,10 +109,20 @@ meta_sl_example <- function() { var = "COMP24FL", label = "Compliance (Week 24)", ) |> - metalite::define_analysis( + define_analysis( + name = "base_char", + title = "Participant Baseline Characteristics by Treatment Group", + label = "baseline characteristic table" + ) |> + define_analysis( name = "trt_compliance", title = "Summary of Treatment Compliance", label = "treatment compliance table" ) |> - metalite::meta_build() + define_analysis( + name = "disp", + title = "Disposition of Participant", + label = "disposition table" + ) |> + meta_build() } diff --git a/R/react_base_char.R b/R/react_base_char.R index c912b71..c2531b9 100644 --- a/R/react_base_char.R +++ b/R/react_base_char.R @@ -80,7 +80,6 @@ react_base_char <- function( x_sl <- metadata_sl |> prepare_sl_summary( population = population, - observation = population, analysis = "base_char", parameter = sl_parameter ) |> diff --git a/R/rtf_base_char.R b/R/rtf_base_char.R index 85eb0d9..2c6b68f 100644 --- a/R/rtf_base_char.R +++ b/R/rtf_base_char.R @@ -195,3 +195,46 @@ rtf_base_char <- function( # Prepare output rtf_output(outdata, path_outdata, path_outtable) } + +#' Format Treatment Compliance Analysis +#' +#' @inheritParams format_base_char +#' +#' @return A list of analysis raw datasets. +#' +#' @export +#' +#' @examples +#' meta <- meta_sl_example() +#' +#' meta |> +#' prepare_trt_compliance(parameter = "comp8;comp16") |> +#' format_trt_compliance() |> +#' rtf_trt_compliance( +#' source = "Source: [CDISCpilot: adam-adsl]", +#' path_outdata = tempfile(fileext = ".Rdata"), +#' path_outtable = tempfile(fileext = ".rtf") +#' ) +rtf_trt_compliance <- rtf_base_char + + +#' Format Disposition Analysis +#' +#' @inheritParams format_base_char +#' +#' @return A list of analysis raw datasets. +#' +#' @export +#' +#' @examples +#' meta <- meta_sl_example() +#' +#' meta |> +#' prepare_disposition(parameter = "disposition;medical-disposition") |> +#' format_disposition() +#' rtf_disposition( +#' source = "Source: [CDISCpilot: adam-adsl]", +#' path_outdata = tempfile(fileext = ".Rdata"), +#' path_outtable = tempfile(fileext = ".rtf") +#' ) +rtf_disposition <- rtf_base_char diff --git a/man/format_base_char.Rd b/man/format_base_char.Rd index 929dc5a..2d859b0 100644 --- a/man/format_base_char.Rd +++ b/man/format_base_char.Rd @@ -33,6 +33,6 @@ Prepare data for baseline characteristic table meta <- meta_sl_example() meta |> - prepare_sl_summary(parameter = "age;gender") |> + prepare_base_char(parameter = "age;gender") |> format_base_char() } diff --git a/man/format_disposition.Rd b/man/format_disposition.Rd new file mode 100644 index 0000000..dd93fd2 --- /dev/null +++ b/man/format_disposition.Rd @@ -0,0 +1,38 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/format_base_char.R +\name{format_disposition} +\alias{format_disposition} +\title{Format Disposition Analysis} +\usage{ +format_disposition( + outdata, + display_col = c("n", "prop", "total"), + digits_prop = 1, + display_stat = c("mean", "sd", "se", "median", "q1 to q3", "range") +) +} +\arguments{ +\item{outdata}{A metadata object created by \code{\link[=prepare_sl_summary]{prepare_sl_summary()}}.} + +\item{display_col}{Column wants to display on the table. +The term could be selected from \code{c("n", "prop", "total")}.} + +\item{digits_prop}{Number of digits for proportion columns.} + +\item{display_stat}{A vector of statistics term name. +The term name could be selected from +\code{c("mean", "sd", "se", "median", "q1 to q3", "range", "q1", "q3", "min", "max")}.} +} +\value{ +A list of analysis raw datasets. +} +\description{ +Format Disposition Analysis +} +\examples{ +meta <- meta_sl_example() + +meta |> + prepare_disposition(parameter = "disposition;medical-disposition") |> + format_disposition() +} diff --git a/man/format_trt_compliance.Rd b/man/format_trt_compliance.Rd new file mode 100644 index 0000000..6e27d67 --- /dev/null +++ b/man/format_trt_compliance.Rd @@ -0,0 +1,38 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/format_base_char.R +\name{format_trt_compliance} +\alias{format_trt_compliance} +\title{Format Treatment Compliance Analysis} +\usage{ +format_trt_compliance( + outdata, + display_col = c("n", "prop", "total"), + digits_prop = 1, + display_stat = c("mean", "sd", "se", "median", "q1 to q3", "range") +) +} +\arguments{ +\item{outdata}{A metadata object created by \code{\link[=prepare_sl_summary]{prepare_sl_summary()}}.} + +\item{display_col}{Column wants to display on the table. +The term could be selected from \code{c("n", "prop", "total")}.} + +\item{digits_prop}{Number of digits for proportion columns.} + +\item{display_stat}{A vector of statistics term name. +The term name could be selected from +\code{c("mean", "sd", "se", "median", "q1 to q3", "range", "q1", "q3", "min", "max")}.} +} +\value{ +A list of analysis raw datasets. +} +\description{ +Format Treatment Compliance Analysis +} +\examples{ +meta <- meta_sl_example() + +meta |> + prepare_trt_compliance(parameter = "comp8;comp16") |> + format_trt_compliance() +} diff --git a/man/prepare_base_char.Rd b/man/prepare_base_char.Rd new file mode 100644 index 0000000..4cec22e --- /dev/null +++ b/man/prepare_base_char.Rd @@ -0,0 +1,36 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/prepare_base_char.R +\name{prepare_base_char} +\alias{prepare_base_char} +\title{Prepare data for treatment compliance table} +\usage{ +prepare_base_char( + meta, + analysis = "base_char", + population = meta$plan[meta$plan$analysis == analysis, ]$population, + parameter = paste(meta$plan[meta$plan$analysis == analysis, ]$parameter, collapse = + ";") +) +} +\arguments{ +\item{meta}{A metadata object created by metalite.} + +\item{analysis}{A character value of analysis term name. +The term name is used as key to link information.} + +\item{population}{A character value of population term name. +The term name is used as key to link information.} + +\item{parameter}{A character value of parameter term name. +The term name is used as key to link information.} +} +\value{ +A list of analysis raw datasets. +} +\description{ +Prepare data for treatment compliance table +} +\examples{ +meta <- meta_sl_example() +meta |> prepare_base_char() +} diff --git a/man/prepare_disposition.Rd b/man/prepare_disposition.Rd new file mode 100644 index 0000000..7ba85ea --- /dev/null +++ b/man/prepare_disposition.Rd @@ -0,0 +1,36 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/prepare_disposition.R +\name{prepare_disposition} +\alias{prepare_disposition} +\title{Prepare data for treatment compliance table} +\usage{ +prepare_disposition( + meta, + analysis = "disp", + population = meta$plan[meta$plan$analysis == analysis, ]$population, + parameter = paste(meta$plan[meta$plan$analysis == analysis, ]$parameter, collapse = + ";") +) +} +\arguments{ +\item{meta}{A metadata object created by metalite.} + +\item{analysis}{A character value of analysis term name. +The term name is used as key to link information.} + +\item{population}{A character value of population term name. +The term name is used as key to link information.} + +\item{parameter}{A character value of parameter term name. +The term name is used as key to link information.} +} +\value{ +A list of analysis raw datasets. +} +\description{ +Prepare data for treatment compliance table +} +\examples{ +meta <- meta_sl_example() +meta |> prepare_base_char() +} diff --git a/man/prepare_sl_summary.Rd b/man/prepare_sl_summary.Rd index 0b01707..b43554e 100644 --- a/man/prepare_sl_summary.Rd +++ b/man/prepare_sl_summary.Rd @@ -1,14 +1,13 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/prepare_base_char.R +% Please edit documentation in R/prepare_sl_summary.R \name{prepare_sl_summary} \alias{prepare_sl_summary} \title{Prepare data for baseline characteristic table} \usage{ prepare_sl_summary( meta, - population = "apat", - observation = "wk12", - analysis = "base_char", + population, + analysis, parameter = paste(names(meta$parameter), collapse = ";") ) } @@ -18,14 +17,14 @@ prepare_sl_summary( \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{analysis}{A character value of analysis term name. The term name is used as key to link information.} \item{parameter}{A character value of parameter 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.} } \value{ A list of analysis raw datasets. diff --git a/man/rtf_disposition.Rd b/man/rtf_disposition.Rd new file mode 100644 index 0000000..e5f76dc --- /dev/null +++ b/man/rtf_disposition.Rd @@ -0,0 +1,39 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/rtf_base_char.R +\name{rtf_disposition} +\alias{rtf_disposition} +\title{Format Disposition Analysis} +\usage{ +rtf_disposition( + outdata, + source, + col_rel_width = NULL, + text_font_size = 9, + orientation = "portrait", + footnotes = NULL, + title = NULL, + path_outdata = NULL, + path_outtable = NULL +) +} +\arguments{ +\item{outdata}{A metadata object created by \code{\link[=prepare_sl_summary]{prepare_sl_summary()}}.} +} +\value{ +A list of analysis raw datasets. +} +\description{ +Format Disposition Analysis +} +\examples{ +meta <- meta_sl_example() + +meta |> + prepare_disposition(parameter = "disposition;medical-disposition") |> + format_disposition() + rtf_disposition( + source = "Source: [CDISCpilot: adam-adsl]", + path_outdata = tempfile(fileext = ".Rdata"), + path_outtable = tempfile(fileext = ".rtf") + ) +} diff --git a/man/rtf_trt_compliance.Rd b/man/rtf_trt_compliance.Rd new file mode 100644 index 0000000..93b5db3 --- /dev/null +++ b/man/rtf_trt_compliance.Rd @@ -0,0 +1,39 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/rtf_base_char.R +\name{rtf_trt_compliance} +\alias{rtf_trt_compliance} +\title{Format Treatment Compliance Analysis} +\usage{ +rtf_trt_compliance( + outdata, + source, + col_rel_width = NULL, + text_font_size = 9, + orientation = "portrait", + footnotes = NULL, + title = NULL, + path_outdata = NULL, + path_outtable = NULL +) +} +\arguments{ +\item{outdata}{A metadata object created by \code{\link[=prepare_sl_summary]{prepare_sl_summary()}}.} +} +\value{ +A list of analysis raw datasets. +} +\description{ +Format Treatment Compliance Analysis +} +\examples{ +meta <- meta_sl_example() + +meta |> + prepare_trt_compliance(parameter = "comp8;comp16") |> + format_trt_compliance() |> + rtf_trt_compliance( + source = "Source: [CDISCpilot: adam-adsl]", + path_outdata = tempfile(fileext = ".Rdata"), + path_outtable = tempfile(fileext = ".rtf") + ) +} diff --git a/vignettes/metalite-sl.Rmd b/vignettes/metalite-sl.Rmd index 89eeec7..64843e0 100644 --- a/vignettes/metalite-sl.Rmd +++ b/vignettes/metalite-sl.Rmd @@ -63,12 +63,7 @@ meta <- meta_adam( group = "TRTA", subset = quote(SAFFL == "Y"), var = c("USUBJID", "TRTA", "SAFFL", "AGEGR1", "SEX", "RACE", "EOSSTT", "EOTSTT1", "COMP8FL", "COMP16FL", "COMP24FL") - ) |> - define_observation( - name = "apat", - group = "TRTA", - subset = quote(SAFFL == "Y"), - var = c("USUBJID", "TRTA", "SAFFL", "AGEGR1", "SEX", "RACE") + ) |> define_parameter( name = "age", @@ -179,8 +174,8 @@ outdata ```{r} outdata |> - format_base_char(display_col = c("n", "prop"), digits_prop = 3) |> - rtf_base_char( + format_trt_compliance(display_col = c("n", "prop"), digits_prop = 3) |> + rtf_trt_compliance( source = "Source: [CDISCpilot: adam-adsl]", path_outdata = tempfile(fileext = ".Rdata"), path_outtable = tempfile(fileext = ".rtf") @@ -197,8 +192,8 @@ outdata ```{r} outdata |> - format_base_char() |> - rtf_base_char( + format_dispostion() |> + rtf_disposition( source = "Source: [CDISCpilot: adam-adsl]", path_outdata = tempfile(fileext = ".Rdata"), path_outtable = tempfile(fileext = ".rtf") From 04a49a435ae0aced1046ba39282e444144fb0b7e Mon Sep 17 00:00:00 2001 From: "Wang, Benjamin" Date: Wed, 12 Jun 2024 15:09:16 -0400 Subject: [PATCH 07/12] fix typo --- vignettes/metalite-sl.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vignettes/metalite-sl.Rmd b/vignettes/metalite-sl.Rmd index 64843e0..d0c2964 100644 --- a/vignettes/metalite-sl.Rmd +++ b/vignettes/metalite-sl.Rmd @@ -192,7 +192,7 @@ outdata ```{r} outdata |> - format_dispostion() |> + format_disposition() |> rtf_disposition( source = "Source: [CDISCpilot: adam-adsl]", path_outdata = tempfile(fileext = ".Rdata"), From 22693c8d41166215cd1c5163e72e1106751d6056 Mon Sep 17 00:00:00 2001 From: "Wang, Benjamin" Date: Wed, 12 Jun 2024 15:38:50 -0400 Subject: [PATCH 08/12] update test case --- NAMESPACE | 1 + R/meta_sl_example.R | 2 +- man/format_ae_specific_subgroup.Rd | 2 +- tests/testthat/test-independent-testing-format_base_char.R | 1 - tests/testthat/test-independent-testing-prepare_base_char.R | 1 - 5 files changed, 3 insertions(+), 4 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 221744d..1f75b7e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,6 +5,7 @@ export(defmt_pct) export(format_base_char) export(format_disposition) export(format_trt_compliance) +export(meta_sl) export(meta_sl_example) export(prepare_base_char) export(prepare_disposition) diff --git a/R/meta_sl_example.R b/R/meta_sl_example.R index 1587873..12c9904 100644 --- a/R/meta_sl_example.R +++ b/R/meta_sl_example.R @@ -52,7 +52,7 @@ meta_sl_example <- function() { analysis = "trt_compliance", population = "apat", observation = "apat", parameter = "comp8;comp16;comp24" ) |> - add_plan( + metalite::add_plan( analysis = "disp", population = "apat", observation = "apat", parameter = "disposition;medical-disposition" ) diff --git a/man/format_ae_specific_subgroup.Rd b/man/format_ae_specific_subgroup.Rd index e26d007..1061892 100644 --- a/man/format_ae_specific_subgroup.Rd +++ b/man/format_ae_specific_subgroup.Rd @@ -16,7 +16,7 @@ format_ae_specific_subgroup( ) } \arguments{ -\item{outdata}{A \code{outdata} object created by \code{\link[metalite.ae:prepare_ae_specific]{prepare_ae_specific()}}.} +\item{outdata}{An \code{outdata} object created by \code{\link[metalite.ae:prepare_ae_specific]{prepare_ae_specific()}}.} \item{display}{A character vector of measurement to be displayed. \itemize{ diff --git a/tests/testthat/test-independent-testing-format_base_char.R b/tests/testthat/test-independent-testing-format_base_char.R index cd0d16c..7b36207 100644 --- a/tests/testthat/test-independent-testing-format_base_char.R +++ b/tests/testthat/test-independent-testing-format_base_char.R @@ -63,7 +63,6 @@ test_meta_base_char <- meta_adam( ) |> prepare_sl_summary( population = "apat", - observation = "apat", analysis = "base_char", parameter = "age;agen;gender;race" ) diff --git a/tests/testthat/test-independent-testing-prepare_base_char.R b/tests/testthat/test-independent-testing-prepare_base_char.R index 81b8c6d..c553e58 100644 --- a/tests/testthat/test-independent-testing-prepare_base_char.R +++ b/tests/testthat/test-independent-testing-prepare_base_char.R @@ -68,7 +68,6 @@ meta_test <- meta_adam( test_meta_base_char <- prepare_sl_summary( meta_test, population = "apat", - observation = "apat", analysis = "base_char", parameter = "age;agen;gender;race" ) From f4bc7d2e54edf699abb0cb43c326b4b9573cb72c Mon Sep 17 00:00:00 2001 From: "Wang, Benjamin" Date: Wed, 12 Jun 2024 15:52:18 -0400 Subject: [PATCH 09/12] add dependency --- R/meta_sl_example.R | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/R/meta_sl_example.R b/R/meta_sl_example.R index 12c9904..7ba8cab 100644 --- a/R/meta_sl_example.R +++ b/R/meta_sl_example.R @@ -62,29 +62,29 @@ meta_sl_example <- function() { observation = adsl ) |> metalite::define_plan(plan) |> - define_population( + metalite::define_population( name = "apat", group = "TRTA", subset = quote(SAFFL == "Y"), var = c("USUBJID", "TRTA", "SAFFL", "AGEGR1", "SEX", "RACE", "EOSSTT", "EOTSTT1", "COMP8FL", "COMP16FL", "COMP24FL") ) |> - define_parameter( + metalite::define_parameter( name = "age", var = "AGE", label = "Age (years)", vargroup = "AGEGR1" ) |> - define_parameter( + metalite::define_parameter( name = "gender", var = "SEX", label = "Gender" ) |> - define_parameter( + metalite::define_parameter( name = "race", var = "RACE", label = "Race" ) |> - define_parameter( + metalite::define_parameter( name = "disposition", var = "EOSSTT", label = "Trial Disposition" @@ -109,20 +109,20 @@ meta_sl_example <- function() { var = "COMP24FL", label = "Compliance (Week 24)", ) |> - define_analysis( + metalite::define_analysis( name = "base_char", title = "Participant Baseline Characteristics by Treatment Group", label = "baseline characteristic table" ) |> - define_analysis( + metalite::define_analysis( name = "trt_compliance", title = "Summary of Treatment Compliance", label = "treatment compliance table" ) |> - define_analysis( + metalite::define_analysis( name = "disp", title = "Disposition of Participant", label = "disposition table" ) |> - meta_build() + metalite::meta_build() } From 3c35e03e902918c744a6445422a0a5bc064a1a05 Mon Sep 17 00:00:00 2001 From: "Wang, Benjamin" Date: Wed, 12 Jun 2024 16:06:26 -0400 Subject: [PATCH 10/12] update document --- R/meta_sl_example.R | 2 +- R/rtf_base_char.R | 4 ++-- man/rtf_disposition.Rd | 21 ++++++++++++++++++++- man/rtf_trt_compliance.Rd | 21 ++++++++++++++++++++- 4 files changed, 43 insertions(+), 5 deletions(-) diff --git a/R/meta_sl_example.R b/R/meta_sl_example.R index 7ba8cab..59bbd4f 100644 --- a/R/meta_sl_example.R +++ b/R/meta_sl_example.R @@ -89,7 +89,7 @@ meta_sl_example <- function() { var = "EOSSTT", label = "Trial Disposition" ) |> - define_parameter( + metalite::define_parameter( name = "medical-disposition", var = "EOTSTT1", label = "Participant Study Medication Disposition" diff --git a/R/rtf_base_char.R b/R/rtf_base_char.R index 2c6b68f..330a5b1 100644 --- a/R/rtf_base_char.R +++ b/R/rtf_base_char.R @@ -198,7 +198,7 @@ rtf_base_char <- function( #' Format Treatment Compliance Analysis #' -#' @inheritParams format_base_char +#' @inheritParams rtf_base_char #' #' @return A list of analysis raw datasets. #' @@ -220,7 +220,7 @@ rtf_trt_compliance <- rtf_base_char #' Format Disposition Analysis #' -#' @inheritParams format_base_char +#' @inheritParams rtf_base_char #' #' @return A list of analysis raw datasets. #' diff --git a/man/rtf_disposition.Rd b/man/rtf_disposition.Rd index e5f76dc..274536a 100644 --- a/man/rtf_disposition.Rd +++ b/man/rtf_disposition.Rd @@ -17,7 +17,26 @@ rtf_disposition( ) } \arguments{ -\item{outdata}{A metadata object created by \code{\link[=prepare_sl_summary]{prepare_sl_summary()}}.} +\item{outdata}{An \code{outdata} object created by \code{\link[=prepare_sl_summary]{prepare_sl_summary()}}.} + +\item{source}{A character value of the data source.} + +\item{col_rel_width}{Column relative width in a vector e.g. c(2,1,1) refers to 2:1:1. +Default is NULL for equal column width.} + +\item{text_font_size}{Text font size. To vary text font size by column, use +numeric vector with length of vector equal to number of columns +displayed e.g. c(9,20,40).} + +\item{orientation}{Orientation in 'portrait' or 'landscape'.} + +\item{footnotes}{A character vector of table footnotes.} + +\item{title}{Term "analysis", "observation" and "population") for collecting title from metadata or a character vector of table titles.} + +\item{path_outdata}{A character string of the outdata path.} + +\item{path_outtable}{A character string of the outtable path.} } \value{ A list of analysis raw datasets. diff --git a/man/rtf_trt_compliance.Rd b/man/rtf_trt_compliance.Rd index 93b5db3..cd4b254 100644 --- a/man/rtf_trt_compliance.Rd +++ b/man/rtf_trt_compliance.Rd @@ -17,7 +17,26 @@ rtf_trt_compliance( ) } \arguments{ -\item{outdata}{A metadata object created by \code{\link[=prepare_sl_summary]{prepare_sl_summary()}}.} +\item{outdata}{An \code{outdata} object created by \code{\link[=prepare_sl_summary]{prepare_sl_summary()}}.} + +\item{source}{A character value of the data source.} + +\item{col_rel_width}{Column relative width in a vector e.g. c(2,1,1) refers to 2:1:1. +Default is NULL for equal column width.} + +\item{text_font_size}{Text font size. To vary text font size by column, use +numeric vector with length of vector equal to number of columns +displayed e.g. c(9,20,40).} + +\item{orientation}{Orientation in 'portrait' or 'landscape'.} + +\item{footnotes}{A character vector of table footnotes.} + +\item{title}{Term "analysis", "observation" and "population") for collecting title from metadata or a character vector of table titles.} + +\item{path_outdata}{A character string of the outdata path.} + +\item{path_outtable}{A character string of the outtable path.} } \value{ A list of analysis raw datasets. From 7363d5324cbad194c3dc330757e3a671a835688d Mon Sep 17 00:00:00 2001 From: "Wang, Benjamin" Date: Wed, 12 Jun 2024 16:32:07 -0400 Subject: [PATCH 11/12] update --- R/prepare_sl_summary.R | 4 +--- man/prepare_sl_summary.Rd | 5 +---- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/R/prepare_sl_summary.R b/R/prepare_sl_summary.R index b52b4f0..5d8d0e2 100644 --- a/R/prepare_sl_summary.R +++ b/R/prepare_sl_summary.R @@ -21,8 +21,6 @@ #' @param meta A metadata object created by metalite. #' @param population A character value of population term name. #' The term name is used as key to link information. -#' @param observation A character value of observation term name. -#' The term name is used as key to link information. #' @param analysis A character value of analysis term name. #' The term name is used as key to link information. #' @param parameter A character value of parameter term name. @@ -34,7 +32,7 @@ #' #' @examples #' meta <- meta_sl_example() -#' meta |> prepare_sl_summary() +#' meta |> prepare_sl_summary(population = "apat", analysis = "base_char") prepare_sl_summary <- function( meta, population, diff --git a/man/prepare_sl_summary.Rd b/man/prepare_sl_summary.Rd index b43554e..d7b9c32 100644 --- a/man/prepare_sl_summary.Rd +++ b/man/prepare_sl_summary.Rd @@ -22,9 +22,6 @@ The term name is used as key to link information.} \item{parameter}{A character value of parameter 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.} } \value{ A list of analysis raw datasets. @@ -34,5 +31,5 @@ Prepare data for baseline characteristic table } \examples{ meta <- meta_sl_example() -meta |> prepare_sl_summary() +meta |> prepare_sl_summary(population = "apat", analysis = "base_char") } From 0d0ef17339eef77c413c622eb809fe3f88cc8c35 Mon Sep 17 00:00:00 2001 From: "Wang, Benjamin" Date: Wed, 12 Jun 2024 16:45:09 -0400 Subject: [PATCH 12/12] update example --- R/rtf_base_char.R | 5 ++--- man/rtf_base_char.Rd | 3 +-- man/rtf_disposition.Rd | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/R/rtf_base_char.R b/R/rtf_base_char.R index 330a5b1..33e1331 100644 --- a/R/rtf_base_char.R +++ b/R/rtf_base_char.R @@ -35,9 +35,8 @@ #' meta <- meta_sl_example() #' #' meta |> -#' prepare_sl_summary( +#' prepare_base_char( #' population = "apat", -#' observation = "apat", #' parameter = "age;gender" #' ) |> #' format_base_char() |> @@ -231,7 +230,7 @@ rtf_trt_compliance <- rtf_base_char #' #' meta |> #' prepare_disposition(parameter = "disposition;medical-disposition") |> -#' format_disposition() +#' format_disposition() |> #' rtf_disposition( #' source = "Source: [CDISCpilot: adam-adsl]", #' path_outdata = tempfile(fileext = ".Rdata"), diff --git a/man/rtf_base_char.Rd b/man/rtf_base_char.Rd index 809eadc..48ac8a3 100644 --- a/man/rtf_base_char.Rd +++ b/man/rtf_base_char.Rd @@ -48,9 +48,8 @@ Baseline characteristic table meta <- meta_sl_example() meta |> - prepare_sl_summary( + prepare_base_char( population = "apat", - observation = "apat", parameter = "age;gender" ) |> format_base_char() |> diff --git a/man/rtf_disposition.Rd b/man/rtf_disposition.Rd index 274536a..743b773 100644 --- a/man/rtf_disposition.Rd +++ b/man/rtf_disposition.Rd @@ -49,7 +49,7 @@ meta <- meta_sl_example() meta |> prepare_disposition(parameter = "disposition;medical-disposition") |> - format_disposition() + format_disposition() |> rtf_disposition( source = "Source: [CDISCpilot: adam-adsl]", path_outdata = tempfile(fileext = ".Rdata"),