Skip to content

Commit

Permalink
Merge pull request #25 from Merck/21-develop-the-prepare_exp_duration…
Browse files Browse the repository at this point in the history
…-for-the-exposure-duration-table

Create prepare function and example for exposure duration
  • Loading branch information
wangben718 committed Jul 9, 2024
2 parents 16d0f16 + dc0b2f0 commit d75b467
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 0 deletions.
61 changes: 61 additions & 0 deletions R/meta_sl_example.R
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,64 @@ meta_sl_example <- function() {
) |>
metalite::meta_build()
}

#' Create an example `meta_sl_exposure_example` object
#'
#' This function is only for illustration purpose.
#' r2rtf is required.
#'
#' @return A metadata object.
#'
#' @export
#'
#' @examples
#' meta_sl_exposure_example()
meta_sl_exposure_example <- function() {
adsl <- r2rtf::r2rtf_adsl

# Create ADEXSUM dataset
adexsum <- data.frame(USUBJID=adsl$USUBJID)
adexsum$TRTA <- factor(adsl$TRT01A,
levels = c("Placebo", "Xanomeline Low Dose", "Xanomeline High Dose"),
labels = c("Placebo", "Low Dose", "High Dose")
)

adexsum$APERIODC <- "Base"
adexsum$APERIOD <- 1
adexsum$AVAL <- sample(x = 0:(24*7), size = length(adexsum$USUBJID), replace = TRUE)
adexsum$EXDURGR <- "not treated"
adexsum$EXDURGR[adexsum$AVAL>=1] <- ">=1 day"
adexsum$EXDURGR[adexsum$AVAL>=7] <- ">=7 days"
adexsum$EXDURGR[adexsum$AVAL>=28] <- ">=28 days"
adexsum$EXDURGR[adexsum$AVAL>=12*7] <- ">=12 weeks"
adexsum$EXDURGR[adexsum$AVAL>=24*7] <- ">=24 weeks"

plan <- metalite::plan(
analysis = "exp_dur", population = "apat",
observation = "apat", parameter = "expdur"
)

meta <- metalite::meta_adam(
population = adexsum,
observation = adexsum
) |>
metalite::define_plan(plan) |>
metalite::define_population(
name = "apat",
group = "TRTA",
subset = quote(APERIOD==1 & AVAL>0),
var = c("USUBJID", "TRTA", "EXDURGR", "AVAL"),
) |>
metalite::define_parameter(
name = "expdur",
var = "AVAL",
label = "Exposure Duration (Days)",
vargroup = "EXDURGR"
)|>
metalite::define_analysis(
name = "exp_dur",
title = "Summary of Exposure Duration",
label = "exposure duration table"
) |>
metalite::meta_build()
}
52 changes: 52 additions & 0 deletions R/prepare_exp_duration.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# 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 exposure duration 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_exposure_example()
#' meta |> prepare_exp_duration()
prepare_exp_duration <- function(meta,
analysis = "exp_dur",
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
)
)

}

0 comments on commit d75b467

Please sign in to comment.