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

Default category setting for extend_exp_duration() #76

Merged
merged 9 commits into from
Feb 19, 2025
10 changes: 3 additions & 7 deletions R/extend_exp_duration.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
#' duration_category_labels = c(">=1 day", ">=7 days", ">=28 days", ">=12 weeks", ">=24 weeks")
#' )
extend_exp_duration <- function(outdata,
category_section_label = NULL,
duration_category_list = NULL,
duration_category_labels = NULL) {
category_section_label = paste0(metalite::collect_adam_mapping(outdata$meta, outdata$parameter)$label, " (extend)"),
duration_category_list = extract_duration_category_ranges(duration_category_labels),
duration_category_labels = levels(outdata$meta$data_population[[metalite::collect_adam_mapping(outdata$meta, outdata$parameter)$vargroup]])) {
res <- outdata
meta <- res$meta
analysis <- res$analysis
Expand Down Expand Up @@ -191,10 +191,6 @@ extend_exp_duration <- function(outdata,
pop_subset <- metalite::collect_adam_mapping(meta, population)$subset
pop_subset <- rlang::quo(TRTDURGR == !!label & !!pop_subset)

if (is.null(category_section_label)) {
category_section_label <- paste0(metalite::collect_adam_mapping(meta, parameter)$label, " (cumulative)")
}

meta_cum <- meta_sl(
data_population,
dataset_observation = NULL,
Expand Down
4 changes: 2 additions & 2 deletions R/meta_sl_example.R
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,14 @@ meta_sl_exposure_example <- function() {
adexsum$APERIOD <- 1

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

adexsum$EXDURGR <- factor(adexsum$EXDURGR,
levels = c(">=1 day and <7days", ">=7 days and <28 days", ">=28 days and <12 weeks", ">=12 weeks and <24 weeks", ">=24 weeks")
levels = c(">=1 day and <7 days", ">=7 days and <28 days", ">=28 days and <12 weeks", ">=12 weeks and <24 weeks", ">=24 weeks")
)

plan <- metalite::plan(
Expand Down
2 changes: 1 addition & 1 deletion R/plotly_exp_duration.R
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ plotly_exp_duration <- function(outdata,
stop("No plot is available. Please check the input data.")
}

histograms <- names(p)
histograms <- plot_type_label
histograms_ids <- paste0("histogram_type_", uuid::UUIDgenerate(), "|", histograms)
plot_divs <- lapply(histograms_ids, function(x) {
element <- unlist(strsplit(x, "\\|"))[2]
Expand Down
59 changes: 59 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,62 @@ rtf_output <- function(

invisible(outdata)
}

#' Obtain a list of category ranges from a character label for exposure duration analysis
#'
#' @param labels A character vector of a category label
#'
#' @noRd
extract_duration_category_ranges <- function(labels) {
times <- labels |>
stringr::str_extract_all(pattern = "\\d+") |>
lapply(function(x) {
if (length(x) == 0) {
stop("A real number for duration category is not recognized. Please rename the category label in the input data, or use `duration_category_list` and `duration_category_labels`.")
}
as.numeric(x)
})

factors <- labels |>
stringr::str_extract_all(pattern = "\\d+ ?([a-zA-Z]+)") |>
lapply(
function(x) {
unit <- stringr::str_extract(x, pattern = "\\d+ ?([a-zA-Z])", group = 1)
factor <- sapply(unit, USE.NAMES = FALSE, function(y) {
if (toupper(y) == "D") {
1
} else if (toupper(y) == "W") {
7
} else if (toupper(y) == "M") {
30.4367
} else if (toupper(y) == "Y") {
365.24
} else {
warning("The unit of duration category is not recognized. The unit is handled as day(s).")
1
}
})
return(factor)
}
)

list <- lapply(
seq_along(times),
function(x) {
if (length(times[[x]]) < 2) {
time <- c(times[[x]], rep(NA, 2 - length(times[[x]])))
} else {
time <- times[[x]]
}
if (length(factors[[x]]) == 1) {
factor <- rep(factors[[x]], 2)
} else if (length(factors[[x]]) == 0) {
factor <- rep(1, 2)
} else {
factor <- factors[[x]]
}
return(time * factor)
}
)
return(list)
}
11 changes: 7 additions & 4 deletions man/extend_exp_duration.Rd

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

2 changes: 1 addition & 1 deletion man/plotly_exp_duration.Rd

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

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

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

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

Loading