Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change function name of base_char #13

Merged
merged 15 commits into from
Jun 19, 2024
3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export(collect_baseline)
export(defmt_pct)
export(format_base_char)
export(meta_sl_example)
export(prepare_base_char)
export(prepare_sl_summary)
export(prepare_trt_compliance)
export(react_base_char)
export(rtf_base_char)
4 changes: 2 additions & 2 deletions R/format_base_char.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand Down
50 changes: 45 additions & 5 deletions R/meta_sl_example.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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()
}
4 changes: 2 additions & 2 deletions R/prepare_base_char.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
53 changes: 53 additions & 0 deletions R/prepare_trt_compliance.R
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

#' 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_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
)
)

}
2 changes: 1 addition & 1 deletion R/react_base_char.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions R/rtf_base_char.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,7 +35,7 @@
#' meta <- meta_sl_example()
#'
#' meta |>
#' prepare_base_char(
#' prepare_sl_summary(
#' population = "apat",
#' observation = "apat",
#' parameter = "age;gender"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions man/format_base_char.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions man/prepare_base_char.Rd → man/prepare_sl_summary.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions man/prepare_trt_compliance.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/rtf_base_char.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testthat/test-independent-testing-format_base_char.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-independent-testing-prepare_base_char.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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))
})
2 changes: 1 addition & 1 deletion tests/testthat/test-independent-testing-rtf_base_char.R
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion vignettes/metalite-sl.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ meta <- meta_adam(

```{r}
outdata <- meta |>
prepare_base_char(
prepare_sl_summary(
population = "apat",
observation = "wk12",
analysis = "base_char",
Expand Down
Loading