Skip to content

Commit

Permalink
Skip running Stan code in tests on CRAN
Browse files Browse the repository at this point in the history
Avoid tripping additional checks (stan-dev/rstan#1111)
  • Loading branch information
dmphillippo committed Feb 15, 2024
1 parent 96e1caa commit c1d4e8e
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 46 deletions.
73 changes: 39 additions & 34 deletions tests/testthat/test-nma.R
Original file line number Diff line number Diff line change
Expand Up @@ -167,40 +167,6 @@ test_that("nma() error if missing values in outcomes or predictors", {
regression = ~x1, center = TRUE)), m)
})

smknet_3l <- combine_network(
set_agd_arm(smkdummy %>% mutate(extra = 0.5, tclass = if_else(trtn == 1, 0, 1)),
studyn, trtn, r = r, n = n, trt_class = tclass),
set_ipd(ipddummy %>% mutate(extra = TRUE, tclass = if_else(trtn == 1, 0, 1)),
studyn, trtn, r = r, trt_class = tclass),
trt_ref = 1) %>%
add_integration(x1 = distr(qnorm, x1_mean, x1_sd),
x2 = distr(qbinom, 1, x2),
x3 = distr(qnorm, x3_mean, x3_sd))

smknet_3c <- combine_network(
set_agd_arm(smkdummy %>% mutate(extra = 0.5, tclass = if_else(trtn == 1, 0, 1)),
studyn, trtn, r = r, n = n, trt_class = tclass),
set_ipd(ipddummy %>% mutate(extra = "a", tclass = if_else(trtn == 1, 0, 1)),
studyn, trtn, r = r, trt_class = tclass),
trt_ref = 1) %>%
add_integration(x1 = distr(qnorm, x1_mean, x1_sd),
x2 = distr(qbinom, 1, x2),
x3 = distr(qnorm, x3_mean, x3_sd))

test_that("nma() silently drops unnecessary columns", {
expect_error(nma(smknet_3l, regression = ~(x1 + x2 + x3):.trt,
prior_intercept = normal(0, 10),
prior_trt = normal(0, 10),
prior_reg = normal(0, 5),
test_grad = TRUE), NA)

expect_error(nma(smknet_3c, regression = ~(x1 + x2 + x3):.trt,
prior_intercept = normal(0, 10),
prior_trt = normal(0, 10),
prior_reg = normal(0, 5),
test_grad = TRUE), NA)
})

test_that("nma.fit() error if only one of x or y provided", {
x <- matrix(1, nrow = 3, ncol = 3)
colnames(x) <- c("a", "b", "c")
Expand Down Expand Up @@ -286,6 +252,45 @@ test_that("nma.fit() error if agd_contrast_Sigma is not right dimensions", {
})


# avoid running Stan models on CRAN
skip_on_cran()


smknet_3l <- combine_network(
set_agd_arm(smkdummy %>% mutate(extra = 0.5, tclass = if_else(trtn == 1, 0, 1)),
studyn, trtn, r = r, n = n, trt_class = tclass),
set_ipd(ipddummy %>% mutate(extra = TRUE, tclass = if_else(trtn == 1, 0, 1)),
studyn, trtn, r = r, trt_class = tclass),
trt_ref = 1) %>%
add_integration(x1 = distr(qnorm, x1_mean, x1_sd),
x2 = distr(qbinom, 1, x2),
x3 = distr(qnorm, x3_mean, x3_sd))

smknet_3c <- combine_network(
set_agd_arm(smkdummy %>% mutate(extra = 0.5, tclass = if_else(trtn == 1, 0, 1)),
studyn, trtn, r = r, n = n, trt_class = tclass),
set_ipd(ipddummy %>% mutate(extra = "a", tclass = if_else(trtn == 1, 0, 1)),
studyn, trtn, r = r, trt_class = tclass),
trt_ref = 1) %>%
add_integration(x1 = distr(qnorm, x1_mean, x1_sd),
x2 = distr(qbinom, 1, x2),
x3 = distr(qnorm, x3_mean, x3_sd))

test_that("nma() silently drops unnecessary columns", {
expect_error(nma(smknet_3l, regression = ~(x1 + x2 + x3):.trt,
prior_intercept = normal(0, 10),
prior_trt = normal(0, 10),
prior_reg = normal(0, 5),
test_grad = TRUE), NA)

expect_error(nma(smknet_3c, regression = ~(x1 + x2 + x3):.trt,
prior_intercept = normal(0, 10),
prior_trt = normal(0, 10),
prior_reg = normal(0, 5),
test_grad = TRUE), NA)
})


single_study_a <- tibble(study = "A", trt = c("a", "b"), r = 500, n = 1000)
net_ss_a <- set_agd_arm(single_study_a, study, trt, r = r, n = n)

Expand Down
28 changes: 16 additions & 12 deletions tests/testthat/test-nodesplit.R
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,6 @@ test_that("nma() nodesplit error if no comparisons to split", {
)
})

test_that("nma() nodesplit warning about ignoring comparisons", {
expect_warning(
nma(thrombo_net,
consistency = "nodesplit",
nodesplit = data.frame(trt1 = "Acc t-PA", trt2 = c("TNK", "ASPAC")),
prior_intercept = normal(scale = 10),
prior_trt = normal(scale = 10),
test_grad = TRUE),
"Ignoring node-split comparisons.+Acc t-PA vs\\. TNK"
)
})

test_that("nma() nodesplit argument validation", {
m1 <- "The data frame passed to `nodesplit` should have two columns"

Expand Down Expand Up @@ -233,6 +221,22 @@ test_that("nma() nodesplit argument validation", {
)
})


# avoid running Stan models on CRAN
skip_on_cran()

test_that("nma() nodesplit warning about ignoring comparisons", {
expect_warning(
nma(thrombo_net,
consistency = "nodesplit",
nodesplit = data.frame(trt1 = "Acc t-PA", trt2 = c("TNK", "ASPAC")),
prior_intercept = normal(scale = 10),
prior_trt = normal(scale = 10),
test_grad = TRUE),
"Ignoring node-split comparisons.+Acc t-PA vs\\. TNK"
)
})

thrombo_ns1 <- nma(thrombo_net,
consistency = "nodesplit",
nodesplit = c("SK", "t-PA"),
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test-plot_integration_error.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@

# avoid running Stan models on CRAN
skip_on_cran()

smk_net <- set_agd_arm(smoking,
study = studyn,
trt = trtc,
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test-posterior_ranks.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@

# avoid running Stan models on CRAN
skip_on_cran()

smk_net <- set_agd_arm(smoking,
study = studyn,
trt = trtc,
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test-predict.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@

# avoid running Stan models on CRAN
skip_on_cran()

smk_net <- set_agd_arm(smoking,
study = studyn,
trt = trtc,
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test-relative_effects.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@

# avoid running Stan models on CRAN
skip_on_cran()

smk_net <- set_agd_arm(smoking,
study = studyn,
trt = trtc,
Expand Down

0 comments on commit c1d4e8e

Please sign in to comment.