Skip to content

Commit

Permalink
Merge pull request Merck#245 from Merck/no-suggests
Browse files Browse the repository at this point in the history
Run code conditionally to pass `noSuggests` check
  • Loading branch information
nanxstats authored May 3, 2024
2 parents d901750 + d13212f commit fbd58a1
Show file tree
Hide file tree
Showing 36 changed files with 123 additions and 18 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: simtrial
Type: Package
Title: Clinical Trial Simulation
Version: 0.4.0
Version: 0.4.1
Authors@R: c(
person("Keaven", "Anderson", email = "[email protected]", role = c("aut")),
person("Yujie", "Zhao", email = "[email protected]", role = c("ctb","cre")),
Expand Down Expand Up @@ -44,6 +44,7 @@ Imports:
future,
methods,
mvtnorm,
rlang,
stats,
survival,
utils
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ importFrom(future,plan)
importFrom(methods,is)
importFrom(mvtnorm,GenzBretz)
importFrom(mvtnorm,pmvnorm)
importFrom(rlang,is_installed)
importFrom(survival,Surv)
importFrom(survival,is.Surv)
importFrom(survival,survfit)
Expand Down
10 changes: 8 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# simtrial 0.4.1

## Improvements

- Pass `noSuggests` checks by running code examples, tests, and vignettes
conditionally if the `Suggests` dependencies are not installed (#243).

# simtrial 0.4.0

## New features
Expand Down Expand Up @@ -56,8 +63,7 @@ performance substantially, and adds new features and documentation.
- Complete overhaul of the API. Function and argument names now use
snake case for consistency and readability. See the
[function reference](https://merck.github.io/simtrial/reference/)
for the updated naming scheme. Detailed change history is available in the
[merged pull requests](https://github.com/Merck/simtrial/pulls?q=is%3Apr+is%3Aclosed)
for the updated naming scheme. Detailed change history is available in the merged pull requests
(thanks, @LittleBeannie, @lili-ling-msd, and @XintongLi2023).
- Dataset names updated to snake case (thanks, @nanxstats, #164).
- The base pipe operator is now used throughout the package.
Expand Down
3 changes: 1 addition & 2 deletions R/get_analysis_date.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@
#'
#' @export
#'
#' @examples
#' @examplesIf rlang::is_installed("gsDesign2")
#' library(gsDesign2)
#' library(simtrial)
#'
#' alpha <- 0.025
#' ratio <- 3
Expand Down
2 changes: 1 addition & 1 deletion R/get_cut_date_by_event.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#'
#' @export
#'
#' @examples
#' @examplesIf rlang::is_installed("dplyr")
#' library(dplyr)
#'
#' # Use default enrollment and calendar cut date
Expand Down
1 change: 0 additions & 1 deletion R/mb_delayed_effect.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#'
#' @examples
#' library(survival)
#' library(dplyr)
#'
#' fit <- survfit(Surv(tte, event) ~ treatment, data = mb_delayed_effect)
#'
Expand Down
2 changes: 1 addition & 1 deletion R/randomize_by_fixed_block.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#'
#' @export
#'
#' @examples
#' @examplesIf rlang::is_installed("dplyr")
#' library(dplyr)
#'
#' # Example 1
Expand Down
2 changes: 1 addition & 1 deletion R/sim_fixed_n.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
#'
#' @export
#'
#' @examples
#' @examplesIf rlang::is_installed("dplyr")
#' library(dplyr)
#' library(future)
#'
Expand Down
2 changes: 1 addition & 1 deletion R/sim_gs_n.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#'
#' @export
#'
#' @examples
#' @examplesIf rlang::is_installed("gsDesign2")
#' library(gsDesign2)
#'
#' # Parameters for enrollment
Expand Down
2 changes: 1 addition & 1 deletion R/sim_pw_surv.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
#'
#' @export
#'
#' @examples
#' @examplesIf rlang::is_installed("dplyr")
#' library(dplyr)
#'
#' # Example 1
Expand Down
4 changes: 4 additions & 0 deletions R/simtrial-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ NULL

#' @importFrom Rcpp sourceCpp
NULL

# For safeguarding code examples and tests
#' @importFrom rlang is_installed
NULL
5 changes: 2 additions & 3 deletions R/wlr_weight.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ mb <- function(delay = 4, w_max = Inf) {
#' "Designing therapeutic cancer vaccine trials with delayed treatment effect."
#' @export
#'
#' @examples
#' library(dplyr)
#' @examplesIf rlang::is_installed("gsDesign2")
#' library(gsDesign2)
#'
#' # Example 1: Unstratified ----
Expand Down Expand Up @@ -136,7 +135,7 @@ mb <- function(delay = 4, w_max = Inf) {
#' sim_pw_surv(
#' n = n, # Sample size
#' # Stratified design with prevalence ratio of 6:4
#' stratum = tibble(stratum = stratum, p = prevalence_ratio),
#' stratum = data.frame(stratum = stratum, p = prevalence_ratio),
#' # Randomization ratio
#' block = c("control", "control", "experimental", "experimental"),
#' enroll_rate = enroll_rate, # Enrollment rate
Expand Down
5 changes: 3 additions & 2 deletions man/early_zero.Rd

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

3 changes: 2 additions & 1 deletion man/get_analysis_date.Rd

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

2 changes: 2 additions & 0 deletions man/get_cut_date_by_event.Rd

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

1 change: 0 additions & 1 deletion man/mb_delayed_effect.Rd

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

2 changes: 2 additions & 0 deletions man/randomize_by_fixed_block.Rd

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

2 changes: 2 additions & 0 deletions man/sim_fixed_n.Rd

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

2 changes: 2 additions & 0 deletions man/sim_gs_n.Rd

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

2 changes: 2 additions & 0 deletions man/sim_pw_surv.Rd

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

10 changes: 10 additions & 0 deletions tests/testthat/test-double_programming_sim_fixed_n.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
test_that("test for sim_fixed_n power comparing to gsDesign results with fixed duration in timing_type=1", {
skip_if_not_installed("gsDesign")

test2 <- test_simfix()$test2
tt1test <- subset(test2, test2$cut == "Planned duration", select = c(event, ln_hr, z, duration, sim))
expect_equal(object = sum(as.integer(tt1test$z < (-1.96))) / 100, expected = 0.94, tolerance = 0.02)
})

test_that("test for sim_fixed_n power comparing to gsDesign results with target events in timing_type=2", {
skip_if_not_installed("gsDesign")

test2 <- test_simfix()$test2
tt2test <- subset(test2, test2$cut == "Targeted events", select = c(event, ln_hr, z, duration, sim))
expect_equal(object = sum(as.integer(tt2test$z < (-1.96))) / 100, expected = 0.93, tolerance = 0.02)
})

test_that("test for events in the correct directions in timing_type=3 comparing to timing_type=2", {
skip_if_not_installed("gsDesign")

test2 <- test_simfix()$test2

tt2test <- subset(test2, test2$cut == "Targeted events", select = c(event, ln_hr, z, duration, sim))
Expand All @@ -30,6 +36,8 @@ test_that("test for events in the correct directions in timing_type=3 comparing
})

test_that("test for timing_type=4 outputs using timing_type 1 and 2 output", {
skip_if_not_installed("gsDesign")

test2 <- test_simfix()$test2

tt1test <- subset(test2, test2$cut == "Planned duration", select = c(event, ln_hr, z, duration, sim))
Expand All @@ -48,6 +56,8 @@ test_that("test for timing_type=4 outputs using timing_type 1 and 2 output", {
})

test_that("test for timing_type=5 outputs using timing_type 2 and 3 output", {
skip_if_not_installed("gsDesign")

test2 <- test_simfix()$test2

tt2test <- subset(test2, test2$cut == "Targeted events", select = c(event, ln_hr, z, duration, sim))
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-double_programming_sim_pw_surv.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
test_that("stratum percentage calculated from simulated dataset must be within
the tolerance=0.002 of stratum in setup (0.4,0.6)", {
skip_if_not_installed("dplyr")

res <- test_sim_pw_surv()
expect_equal(
object = c(
Expand All @@ -12,19 +14,25 @@ test_that("stratum percentage calculated from simulated dataset must be within

test_that("block calculated from simulated dataset equals size of 4 with 1:1
randomization, which is 2 for each arm", {
skip_if_not_installed("dplyr")

res <- test_sim_pw_surv()
expect_equal(object = res$bktest1, expected = rep(2, length(res$bktest1)))
expect_equal(object = res$bktest2, expected = rep(2, length(res$bktest2)))
})

test_that("fail_rate calculated from simulated dataset must be within the
tolerance=0.1 of fail_rate in setting", {
skip_if_not_installed("dplyr")

res <- test_sim_pw_surv()
expect_equal(object = res$ratetest, expected = res$fail_rate$rate, tolerance = 0.1)
})

test_that("dropout_rate calculated from simulated dataset must be within
the tolerance=0.0005 of dropout_rate=0.001 in setup", {
skip_if_not_installed("dplyr")

res <- test_sim_pw_surv()
duration <- 300
drtest <- 0
Expand All @@ -36,6 +44,8 @@ test_that("dropout_rate calculated from simulated dataset must be within

test_that("enroll_rate calculated from simulated dataset must be within
the relative tolerance=0.05 of enroll_rate in setup", {
skip_if_not_installed("dplyr")

res <- test_sim_pw_surv()
duration <- 300
entest <- 0
Expand All @@ -49,6 +59,8 @@ test_that("enroll_rate calculated from simulated dataset must be within
})

test_that("The actual number of events changes by changing total sample size", {
skip_if_not_installed("dplyr")

res1 <- test_sim_pw_surv()
res2 <- test_sim_pw_surv_2()
expect_false(unique(res1$xevent$event == res2$zevent$event))
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-independent_test_counting_process.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
test_that("Counting Process Format without ties", {
skip_if_not_installed("dplyr")

x <- data.frame(
stratum = c(rep(1, 10), rep(2, 6)),
treatment = rep(c(1, 1, 0, 0), 4),
Expand All @@ -18,6 +20,8 @@ test_that("Counting Process Format without ties", {
})

test_that("Counting Process Format with ties", {
skip_if_not_installed("dplyr")

x <- data.frame(
stratum = c(rep(1, 10), rep(2, 6)),
treatment = rep(c(1, 1, 0, 0), 4),
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-independent_test_cut_data_by_date.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ test_that("x is a time-to-event data set", {
})

test_that("only patients recorded by cut_data_by_date are included", {
skip_if_not_installed("dplyr")

x <- sim_pw_surv(n = 200)
cut_date <- 10
xcut <- cut_data_by_date(x, cut_date)
Expand All @@ -30,6 +32,8 @@ test_that("Time-to-event (TTE) is cut off at the cut_date", {
})

test_that("the event variable is calculated correctly", {
skip_if_not_installed("dplyr")

x <- sim_pw_surv(n = 200)
cut_date <- 10
xcut <- cut_data_by_date(x, cut_date)
Expand Down
Loading

0 comments on commit fbd58a1

Please sign in to comment.