Skip to content

Commit

Permalink
Merge 62cc1b3 into e887629
Browse files Browse the repository at this point in the history
  • Loading branch information
edelarua authored Oct 14, 2022
2 parents e887629 + 62cc1b3 commit 237b0fd
Show file tree
Hide file tree
Showing 95 changed files with 484 additions and 523 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: tern
Title: Create Common TLGs Used in Clinical Trials
Version: 0.7.10
Version: 0.7.10.9000
Date: 2022-10-14
Authors@R: c(
person("Joe", "Zhu", , "[email protected]", role = c("aut", "cre")),
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# tern 0.7.10.9000

### Enhancements
* Replaced `synthetic_cdisc_data` with refactored `synthetic_cdisc_dataset` function to speed up dataset loading in tests/examples.
* Updated all tests to use `rcd_2022_06_27` version of cached data.

# tern 0.7.10

### New Features
Expand Down
3 changes: 1 addition & 2 deletions R/abnormal_by_worst_grade.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ NULL
#' library(scda)
#' library(dplyr)
#' library(forcats)
#'
#' adlb <- synthetic_cdisc_data("latest")$adlb
#' adlb <- synthetic_cdisc_dataset("latest", "adlb")
#'
#' # Data is modified in order to have some parameters with grades only in one direction
#' # and simulate the real data.
Expand Down
5 changes: 2 additions & 3 deletions R/abnormal_by_worst_grade_worsen.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ NULL
#' for the high direction.
#'
#' @examples
#'
#' library(scda)
#' library(dplyr)
#' adlb <- synthetic_cdisc_data("latest")$adlb
#' adsl <- synthetic_cdisc_data("latest")$adsl
#' adsl <- synthetic_cdisc_dataset("latest", "adsl")
#' adlb <- synthetic_cdisc_dataset("latest", "adlb")
#'
#' # The direction variable, GRADDR, is based on metadata
#' adlb <- adlb %>%
Expand Down
12 changes: 7 additions & 5 deletions R/count_cumulative.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ h_count_cumulative <- function(x,
checkmate::assert_flag(na.rm)

is_keep <- if (na.rm) !is.na(x) else rep(TRUE, length(x))
count <- if (lower_tail & include_eq) {
count <- if (lower_tail && include_eq) {
length(x[is_keep & x <= threshold])
} else if (lower_tail & !include_eq) {
} else if (lower_tail && !include_eq) {
length(x[is_keep & x < threshold])
} else if (!lower_tail & include_eq) {
} else if (!lower_tail && include_eq) {
length(x[is_keep & x >= threshold])
} else if (!lower_tail & !include_eq) {
} else if (!lower_tail && !include_eq) {
length(x[is_keep & x > threshold])
}

Expand Down Expand Up @@ -137,7 +137,8 @@ a_count_cumulative <- make_afun(
#' @export
#' @examples
#' library(scda)
#' ADSL <- synthetic_cdisc_data("latest")$adsl
#' ADSL <- synthetic_cdisc_dataset("latest", "adsl")
#'
#' basic_table() %>%
#' split_cols_by("ARM") %>%
#' add_colcounts() %>%
Expand All @@ -146,6 +147,7 @@ a_count_cumulative <- make_afun(
#' thresholds = c(40, 60)
#' ) %>%
#' build_table(ADSL)
#'
count_cumulative <- function(lyt,
vars,
var_labels = vars,
Expand Down
5 changes: 3 additions & 2 deletions R/count_missed_doses.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ a_count_missed_doses <- make_afun(
#' @examples
#' library(dplyr)
#' library(scda)
#' adex <- synthetic_cdisc_data("latest")$adex
#' adsl <- synthetic_cdisc_data("latest")$adsl
#' adex <- synthetic_cdisc_dataset("latest", "adex")
#' adsl <- synthetic_cdisc_dataset("latest", "adsl")
#'
#' anl <- adex %>%
#' distinct(STUDYID, USUBJID, ARM) %>%
#' mutate(
Expand Down
6 changes: 2 additions & 4 deletions R/count_patients_with_event.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ NULL
#' @export
#'
#' @examples
#'
#'
#' library(dplyr)
#' library(scda)
#' adae <- synthetic_cdisc_data("latest")$adae
#' adsl <- synthetic_cdisc_data("latest")$adsl
#' adae <- synthetic_cdisc_dataset("latest", "adae")
#' adsl <- synthetic_cdisc_dataset("latest", "adsl")
#'
#' # `s_count_patients_with_event()`
#'
Expand Down
26 changes: 13 additions & 13 deletions R/coxph.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,18 @@ rht <- function(x) {
#' library(scda)
#' library(survival)
#'
#' ADSL <- synthetic_cdisc_data("latest")$adsl
#' ADSL <- synthetic_cdisc_dataset("latest", "adsl")
#' ADSL <- ADSL %>%
#' filter(SEX %in% c("F", "M"))
#'
#' ADTTE <- synthetic_cdisc_data("latest")$adtte %>%
#' adtte <- synthetic_cdisc_dataset("latest", "adtte") %>%
#' filter(PARAMCD == "PFS")
#' ADTTE$ARMCD <- droplevels(ADTTE$ARMCD)
#' ADTTE$SEX <- droplevels(ADTTE$SEX)
#' adtte$ARMCD <- droplevels(adtte$ARMCD)
#' adtte$SEX <- droplevels(adtte$SEX)
#'
#' mod <- coxph(
#' formula = Surv(time = AVAL, event = 1 - CNSR) ~ (SEX + ARMCD)^2,
#' data = ADTTE
#' data = adtte
#' )
#'
#' mmat <- stats::model.matrix(mod)[1, ]
Expand Down Expand Up @@ -299,7 +299,7 @@ check_formula <- function(formula) {


check_covariate_formulas <- function(covariates) {
if (!all(vapply(X = covariates, FUN = inherits, what = "formula", FUN.VALUE = TRUE)) | is.null(covariates)) {
if (!all(vapply(X = covariates, FUN = inherits, what = "formula", FUN.VALUE = TRUE)) || is.null(covariates)) {
stop("Check `covariates`, it should be a list of right-hand-term formulas, e.g. list(Age = ~AGE).")
}

Expand Down Expand Up @@ -363,21 +363,21 @@ check_increments <- function(increments, covariates) {
#' library(scda)
#' library(dplyr)
#'
#' ADTTE <- synthetic_cdisc_data("latest")$adtte
#' ADTTE_f <- subset(ADTTE, PARAMCD == "OS") # _f: filtered
#' ADTTE_f <- filter(
#' ADTTE_f,
#' adtte <- synthetic_cdisc_dataset("latest", "adtte")
#' adtte_f <- subset(adtte, PARAMCD == "OS") # _f: filtered
#' adtte_f <- filter(
#' adtte_f,
#' PARAMCD == "OS" &
#' SEX %in% c("F", "M") &
#' RACE %in% c("ASIAN", "BLACK OR AFRICAN AMERICAN", "WHITE")
#' )
#' ADTTE_f$SEX <- droplevels(ADTTE_f$SEX)
#' ADTTE_f$RACE <- droplevels(ADTTE_f$RACE)
#' adtte_f$SEX <- droplevels(adtte_f$SEX)
#' adtte_f$RACE <- droplevels(adtte_f$RACE)
#'
#' # Internal function - s_cox_multivariate
#' \dontrun{
#' s_cox_multivariate(
#' formula = Surv(time = AVAL, event = 1 - CNSR) ~ (ARMCD + RACE + AGE)^2, data = ADTTE_f
#' formula = Surv(time = AVAL, event = 1 - CNSR) ~ (ARMCD + RACE + AGE)^2, data = adtte_f
#' )
#' }
#'
Expand Down
3 changes: 1 addition & 2 deletions R/fit_rsp_step.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@
#' customization options.
#' @export
#' @examples
#'
#' # Testing dataset with just two treatment arms.
#' library(survival)
#' library(dplyr)
#' library(scda)
#'
#' adrs <- synthetic_cdisc_data("latest")$adrs
#' adrs <- synthetic_cdisc_dataset("latest", "adrs")
#' adrs_f <- adrs %>%
#' filter(
#' PARAMCD == "BESRSPI",
Expand Down
3 changes: 1 addition & 2 deletions R/fit_survival_step.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@
#' @seealso [control_step()] and [control_coxph()] for the available customization options.
#' @export
#' @examples
#'
#' # Testing dataset with just two treatment arms.
#' library(scda)
#' library(dplyr)
#' library(rtables)
#'
#' adtte <- synthetic_cdisc_data("latest")$adtte
#' adtte <- synthetic_cdisc_dataset("latest", "adtte")
#'
#' adtte_f <- adtte %>%
#' filter(
Expand Down
5 changes: 3 additions & 2 deletions R/g_forest.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
#' library(forcats)
#' library(rtables)
#' library(nestcolor)
#' adrs <- synthetic_cdisc_data("latest")$adrs
#'
#' adrs <- synthetic_cdisc_dataset("latest", "adrs")
#' n_records <- 20
#' adrs_labels <- formatters::var_labels(adrs, fill = TRUE)
#' adrs <- adrs %>%
Expand Down Expand Up @@ -82,7 +83,7 @@
#' draw_grob(p)
#'
#' # Survival forest plot example.
#' adtte <- synthetic_cdisc_data("latest")$adtte
#' adtte <- synthetic_cdisc_dataset("latest", "adtte")
#' # Save variable labels before data processing steps.
#' adtte_labels <- formatters::var_labels(adtte, fill = TRUE)
#' adtte_f <- adtte %>%
Expand Down
6 changes: 3 additions & 3 deletions R/g_lineplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@
#' @export
#'
#' @examples
#' library(scda)
#' library(nestcolor)
#'
#' cached_data <- scda::synthetic_cdisc_data("latest")
#' adsl <- cached_data$adsl
#' adlb <- cached_data$adlb
#' adsl <- synthetic_cdisc_dataset("latest", "adsl")
#' adlb <- synthetic_cdisc_dataset("latest", "adlb")
#' adlb <- dplyr::filter(adlb, ANL01FL == "Y", PARAMCD == "ALT", AVISIT != "SCREENING")
#' adlb$AVISIT <- droplevels(adlb$AVISIT)
#' adlb <- dplyr::mutate(adlb, AVISIT = forcats::fct_reorder(AVISIT, AVISITN, min))
Expand Down
4 changes: 2 additions & 2 deletions R/g_waterfall.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
#' library(scda)
#' library(dplyr)
#'
#' ADSL <- synthetic_cdisc_data("latest")$adsl
#' ADSL <- synthetic_cdisc_dataset("latest", "adsl")
#' ADSL_f <- ADSL %>%
#' select(USUBJID, STUDYID, ARM, ARMCD, SEX)
#'
#' ADRS <- synthetic_cdisc_data("latest")$adrs
#' ADRS <- synthetic_cdisc_dataset("latest", "adrs")
#' ADRS_f <- ADRS %>%
#' filter(PARAMCD == "OVRINV") %>%
#' mutate(pchg = rnorm(n(), 10, 50))
Expand Down
4 changes: 2 additions & 2 deletions R/h_adsl_adlb_merge_using_worst_flag.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
#'
#' @examples
#' library(scda)
#' adlb <- synthetic_cdisc_data("latest")$adlb
#' adsl <- synthetic_cdisc_data("latest")$adsl
#' adlb <- synthetic_cdisc_dataset("latest", "adlb")
#' adsl <- synthetic_cdisc_dataset("latest", "adsl")
#'
#' # `h_adsl_adlb_merge_using_worst_flag`
#' adlb_out <- h_adsl_adlb_merge_using_worst_flag(adsl, adlb, worst_flag = c("WGRHIFL" = "Y"))
Expand Down
2 changes: 1 addition & 1 deletion R/h_map_for_count_abnormal.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#'
#' @examples
#' library(scda)
#' adlb <- synthetic_cdisc_data("latest")$adlb
#' adlb <- synthetic_cdisc_dataset("latest", "adlb")
#' adlb <- df_explicit_na(adlb)
#'
#' h_map_for_count_abnormal(
Expand Down
2 changes: 1 addition & 1 deletion R/h_pkparam_sort.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#' library(scda)
#' library(dplyr)
#'
#' adpp <- synthetic_cdisc_data("latest")$adpp
#' adpp <- synthetic_cdisc_dataset("latest", "adpp")
#' adpp <- adpp %>% mutate(PKPARAM = factor(paste0(PARAM, " (", AVALU, ")")))
#'
#' pk_ordered_data <- h_pkparam_sort(adpp)
Expand Down
2 changes: 1 addition & 1 deletion R/h_response_biomarkers_subgroups.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#' library(forcats)
#' library(rtables)
#'
#' adrs <- synthetic_cdisc_data("latest")$adrs
#' adrs <- synthetic_cdisc_dataset("latest", "adrs")
#' adrs_labels <- formatters::var_labels(adrs)
#'
#' adrs_f <- adrs %>%
Expand Down
2 changes: 1 addition & 1 deletion R/h_response_subgroups.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#' library(forcats)
#' library(rtables)
#'
#' adrs <- synthetic_cdisc_data("latest")$adrs
#' adrs <- synthetic_cdisc_dataset("latest", "adrs")
#' adrs_labels <- formatters::var_labels(adrs)
#'
#' adrs_f <- adrs %>%
Expand Down
2 changes: 1 addition & 1 deletion R/h_stack_by_baskets.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#' @examples
#' library(scda)
#'
#' adae <- synthetic_cdisc_data("latest")$adae[1:20, ] %>% df_explicit_na()
#' adae <- synthetic_cdisc_dataset("latest", "adae")[1:20, ] %>% df_explicit_na()
#' h_stack_by_baskets(df = adae)
#'
#' aag <- data.frame(
Expand Down
2 changes: 1 addition & 1 deletion R/h_survival_biomarkers_subgroups.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#' library(forcats)
#' library(rtables)
#'
#' adtte <- synthetic_cdisc_data("latest")$adtte
#' adtte <- synthetic_cdisc_dataset("latest", "adtte")
#'
#' # Save variable labels before data processing steps.
#' adtte_labels <- formatters::var_labels(adtte, fill = FALSE)
Expand Down
2 changes: 1 addition & 1 deletion R/h_survival_duration_subgroups.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#' library(forcats)
#' library(rtables)
#'
#' adtte <- synthetic_cdisc_data("latest")$adtte
#' adtte <- synthetic_cdisc_dataset("latest", "adtte")
#'
#' # Save variable labels before data processing steps.
#' adtte_labels <- formatters::var_labels(adtte)
Expand Down
3 changes: 1 addition & 2 deletions R/individual_patient_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@ NULL
#' @inheritParams argument_convention
#' @export
#' @examples
#'
#' library(scda)
#' library(dplyr)
#' library(nestcolor)
#'
#' # Select a small sample of data to plot.
#' adlb <- synthetic_cdisc_data("latest")$adlb %>%
#' adlb <- synthetic_cdisc_dataset("latest", "adlb") %>%
#' filter(PARAMCD == "ALT", !(AVISIT %in% c("SCREENING", "BASELINE"))) %>%
#' slice(1:36)
#'
Expand Down
Loading

0 comments on commit 237b0fd

Please sign in to comment.