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

ignore missmatch in grid argument #734

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 47 additions & 37 deletions tests/testthat/test-kmg01.R
Original file line number Diff line number Diff line change
@@ -1,57 +1,67 @@
# kmg01 functions ----

test_that("kmg01 works as expected", {
filter_data <- dunlin::log_filter(syn_data, PARAMCD == "OS", "adtte")
pre_data <- expect_silent(kmg01_pre(filter_data, dataset = "adtte"))
raw_res <- expect_silent(kmg01_main(pre_data, dataset = "adtte"))
expect_true(ggplot2::is.ggplot(raw_res))
withr::with_options(opts_partial_match_old, {
filter_data <- dunlin::log_filter(syn_data, PARAMCD == "OS", "adtte")
pre_data <- expect_silent(kmg01_pre(filter_data, dataset = "adtte"))
raw_res <- expect_silent(kmg01_main(pre_data, dataset = "adtte"))
expect_true(ggplot2::is.ggplot(raw_res))
})
})

# kmg01 ----

test_that("kmg01 works as expected with custom color set", {
col <- c(
"A: Drug X" = "black",
"B: Placebo" = "blue",
"C: Combination" = "gray"
)

filter_data <- dunlin::log_filter(syn_data, PARAMCD == "OS", "adtte")
res <- expect_silent(run(kmg01, filter_data, dataset = "adtte", col = col))
expect_true(ggplot2::is.ggplot(res))
res <- expect_silent(run(kmg01, filter_data, dataset = "adtte", col = unname(col)))
expect_true(ggplot2::is.ggplot(res))
withr::with_options(opts_partial_match_old, {
col <- c(
"A: Drug X" = "black",
"B: Placebo" = "blue",
"C: Combination" = "gray"
)

filter_data <- dunlin::log_filter(syn_data, PARAMCD == "OS", "adtte")
res <- expect_silent(run(kmg01, filter_data, dataset = "adtte", col = col))
expect_true(ggplot2::is.ggplot(res))
res <- expect_silent(run(kmg01, filter_data, dataset = "adtte", col = unname(col)))
expect_true(ggplot2::is.ggplot(res))
})
})

test_that("kmg01 works if change pvalue, ties and conf level", {
filter_data <- dunlin::log_filter(syn_data, PARAMCD == "OS", "adtte")
res <- expect_silent(run(kmg01, filter_data,
dataset = "adtte",
pval_method = "log-rank",
ties = "efron",
conf_level = 0.99
))
expect_true(ggplot2::is.ggplot(res))
withr::with_options(opts_partial_match_old, {
filter_data <- dunlin::log_filter(syn_data, PARAMCD == "OS", "adtte")
res <- expect_silent(run(kmg01, filter_data,
dataset = "adtte",
pval_method = "log-rank",
ties = "efron",
conf_level = 0.99
))
expect_true(ggplot2::is.ggplot(res))
})
})


test_that("kmg01 works if change annotation position", {
filter_data <- dunlin::log_filter(syn_data, PARAMCD == "OS", "adtte")
res <- expect_silent(run(kmg01, filter_data,
dataset = "adtte", annot_surv_med = FALSE, annot_coxph = TRUE,
control_annot_coxph = control_coxph_annot(x = 0.78, y = 0.9)
))
expect_true(ggplot2::is.ggplot(res))
withr::with_options(opts_partial_match_old, {
filter_data <- dunlin::log_filter(syn_data, PARAMCD == "OS", "adtte")
res <- expect_silent(run(kmg01, filter_data,
dataset = "adtte", annot_surv_med = FALSE, annot_coxph = TRUE,
control_annot_coxph = control_coxph_annot(x = 0.78, y = 0.9)
))
expect_true(ggplot2::is.ggplot(res))
})
})


test_that("kmg01 works for stratified analysis", {
filter_data <- dunlin::log_filter(syn_data, PARAMCD == "OS", "adtte")
res <- expect_silent(run(kmg01, filter_data,
dataset = "adtte", annot_surv_med = FALSE,
position_coxph = c(0.4, 0.5),
position_surv_med = c(1, 0.7),
strata = c("STRATA1", "STRATA2")
))
expect_true(ggplot2::is.ggplot(res))
withr::with_options(opts_partial_match_old, {
filter_data <- dunlin::log_filter(syn_data, PARAMCD == "OS", "adtte")
res <- expect_silent(run(kmg01, filter_data,
dataset = "adtte", annot_surv_med = FALSE,
control_annot_coxph = tern::control_coxph_annot(x = 0.4, y = 0.5),
control_annot_surv_med = tern::control_surv_med_annot(x = 0.99, y = 0.7),
strata = c("STRATA1", "STRATA2")
))
expect_true(ggplot2::is.ggplot(res))
})
})
202 changes: 111 additions & 91 deletions tests/testthat/test-mng01.R
Original file line number Diff line number Diff line change
@@ -1,116 +1,136 @@
# mng01 functions ---

test_that("mng01 works as expected with default argument values", {
pre_data <- mng01_pre(syn_data, dataset = "adlb")
res <- mng01_main(pre_data, dataset = "adlb")
expect_list(res, len = 3, types = "ggplot")

skip_on_ci()
vdiffr::expect_doppelganger("mng01 with default value", res[[1]])
withr::with_options(opts_partial_match_old, {
pre_data <- mng01_pre(syn_data, dataset = "adlb")
res <- mng01_main(pre_data, dataset = "adlb")
expect_list(res, len = 3, types = "ggplot")

skip_on_ci()
vdiffr::expect_doppelganger("mng01 with default value", res[[1]])
})
})

test_that("mng01 works as expected with custom argument values", {
col <- c(
"B: Placebo" = "black",
"A: Drug X" = "blue",
"C: Combination" = "gray"
)

pre_data <- mng01_pre(syn_data, dataset = "adlb")
res <- mng01_main(
pre_data,
dataset = "adlb",
ggtheme = ggplot2::theme(axis.text.x = ggplot2::element_text(colour = "red", angle = 30, hjust = 1)),
line_col = col
)
expect_list(res, len = 3, types = "ggplot")

bad_col <- c(
"B: Placebo" = "black",
"A: Drug X" = "blue"
)

expect_error(
mng01_main(pre_data, dataset = "adlb", line_col = bad_col),
"Missing color matching for C: Combination",
fixed = TRUE
)

skip_on_ci()
vdiffr::expect_doppelganger("mng01 with custom theme", res[[1]], )
withr::with_options(opts_partial_match_old, {
col <- c(
"B: Placebo" = "black",
"A: Drug X" = "blue",
"C: Combination" = "gray"
)

pre_data <- mng01_pre(syn_data, dataset = "adlb")

res <- mng01_main(
pre_data,
dataset = "adlb",
ggtheme = ggplot2::theme(axis.text.x = ggplot2::element_text(colour = "red", angle = 30, hjust = 1)),
line_col = col
)

expect_list(res, len = 3, types = "ggplot")

bad_col <- c(
"B: Placebo" = "black",
"A: Drug X" = "blue"
)

expect_error(
mng01_main(pre_data, dataset = "adlb", line_col = bad_col),
"Missing color matching for C: Combination",
fixed = TRUE
)

skip_on_ci()
vdiffr::expect_doppelganger("mng01 with custom theme", res[[1]])
})
})


# mng01 ----

test_that("mng01 works as expected with custom color set", {
col <- c(
"B: Placebo" = "black",
"A: Drug X" = "blue",
"C: Combination" = "gray"
)

proc_data <- syn_data
res <- run(mng01, proc_data, dataset = "adlb", line_col = col)
expect_list(res, len = 3, types = "ggplot")

res2 <- run(mng01, proc_data, dataset = "adlb", line_col = unname(col))
expect_list(res2, len = 3, types = "ggplot")

skip_on_ci()
vdiffr::expect_doppelganger("run mng01 with custom color set", res[[1]])
vdiffr::expect_doppelganger("run mng01 with custom unnamed color set", res2[[1]])
withr::with_options(opts_partial_match_old, {
col <- c(
"B: Placebo" = "black",
"A: Drug X" = "blue",
"C: Combination" = "gray"
)
proc_data <- syn_data

res <- run(mng01, proc_data, dataset = "adlb", line_col = col)
expect_list(res, len = 3, types = "ggplot")

res2 <- run(mng01, proc_data, dataset = "adlb", line_col = unname(col))
expect_list(res2, len = 3, types = "ggplot")

skip_on_ci()
vdiffr::expect_doppelganger("run mng01 with custom color set", res[[1]])
vdiffr::expect_doppelganger("run mng01 with custom unnamed color set", res2[[1]])
})
})

test_that("mng01 works with table = NULL", {
proc_data <- syn_data
res <- run(mng01, proc_data, dataset = "adlb", table = NULL)
expect_list(res, len = 3, types = "ggplot")

skip_on_ci()
vdiffr::expect_doppelganger("run mng01 without table", res[[1]])
withr::with_options(opts_partial_match_old, {
proc_data <- syn_data
res <- run(mng01, proc_data, dataset = "adlb", table = NULL)
expect_list(res, len = 3, types = "ggplot")

skip_on_ci()
vdiffr::expect_doppelganger("run mng01 without table", res[[1]])
})
})

test_that("mng01 works with combination of x variables", {
proc_data <- syn_data
res <- run(
mng01,
proc_data,
dataset = "adlb",
x_var = c("AVISIT", "AVISITN")
)
expect_list(res, len = 3, types = "ggplot")

skip_on_ci()
vdiffr::expect_doppelganger("run mng01 with combination of x variables", res[[1]])
withr::with_options(opts_partial_match_old, {
proc_data <- syn_data
res <- run(
mng01,
proc_data,
dataset = "adlb",
x_var = c("AVISIT", "AVISITN")
)

expect_list(res, len = 3, types = "ggplot")

skip_on_ci()
vdiffr::expect_doppelganger("run mng01 with combination of x variables", res[[1]])
})
})

test_that("mng01 works with numeric x variable", {
proc_data <- syn_data
proc_data$adlb$AVISITN[1:20] <- 10
proc_data$adlb$AVISITN[21:40] <- -3
res <- run(
mng01,
proc_data,
dataset = "adlb",
x_var = c("AVISITN")
)
expect_list(res, len = 3, types = "ggplot")

skip_on_ci()
vdiffr::expect_doppelganger("run mng01 with numeric x variables", res[[1]])
withr::with_options(opts_partial_match_old, {
proc_data <- syn_data
proc_data$adlb$AVISITN[1:20] <- 10
proc_data$adlb$AVISITN[21:40] <- -3

res <- run(
mng01,
proc_data,
dataset = "adlb",
x_var = c("AVISITN")
)

expect_list(res, len = 3, types = "ggplot")

skip_on_ci()
vdiffr::expect_doppelganger("run mng01 with numeric x variables", res[[1]])
})
})

test_that("mng01 works with numeric jitter", {
proc_data <- syn_data
res <- run(
mng01,
proc_data,
dataset = "adlb",
jitter = 0.7
)
expect_list(res, len = 3, types = "ggplot")

skip_on_ci()
vdiffr::expect_doppelganger("run mng01 with jitter", res[[1]])
withr::with_options(opts_partial_match_old, {
proc_data <- syn_data

res <- run(
mng01,
proc_data,
dataset = "adlb",
jitter = 0.7
)

expect_list(res, len = 3, types = "ggplot")
skip_on_ci()
vdiffr::expect_doppelganger("run mng01 with jitter", res[[1]])
})
})
Loading