Skip to content

Commit

Permalink
Add argument matching back in
Browse files Browse the repository at this point in the history
  • Loading branch information
edelarua committed Oct 8, 2024
1 parent 946abec commit 9b4b80f
Showing 1 changed file with 59 additions and 31 deletions.
90 changes: 59 additions & 31 deletions tests/testthat/test-odds_ratio.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ testthat::test_that("or_clogit estimates right OR and CI", {
stringsAsFactors = TRUE
)

result <- or_clogit(data, conf_level = 0.95)
# https://github.com/therneau/survival/issues/240
withr::with_options(
opts_partial_match_old,
result <- or_clogit(data, conf_level = 0.95)
)

# from SAS
res <- testthat::expect_silent(result)
Expand Down Expand Up @@ -62,13 +66,17 @@ testthat::test_that("s_odds_ratio estimates right OR and CI (stratified analysis
strata = factor(sample(c("C", "D"), 100, TRUE))
)

result <- s_odds_ratio(
df = subset(dta, grp == "A"),
.var = "rsp",
.ref_group = subset(dta, grp == "B"),
.in_ref_col = FALSE,
.df_row = dta,
variables = list(arm = "grp", strata = "strata")
# https://github.com/therneau/survival/issues/240
withr::with_options(
opts_partial_match_old,
result <- s_odds_ratio(
df = subset(dta, grp == "A"),
.var = "rsp",
.ref_group = subset(dta, grp == "B"),
.in_ref_col = FALSE,
.df_row = dta,
variables = list(arm = "grp", strata = "strata")
)
)

res <- testthat::expect_silent(result)
Expand All @@ -86,15 +94,19 @@ testthat::test_that("s_odds_ratio returns error for incorrect groups", {
"Arms A+B" = c("A", "B")
)

testthat::expect_error(result <- s_odds_ratio(
df = subset(data, grp == "A"),
.var = "rsp",
.ref_group = subset(data, grp == "B"),
.in_ref_col = FALSE,
.df_row = data,
variables = list(arm = "grp", strata = "strata"),
groups_list = groups
))
# https://github.com/therneau/survival/issues/240
withr::with_options(
opts_partial_match_old,
result <- testthat::expect_error(s_odds_ratio(
df = subset(data, grp == "A"),
.var = "rsp",
.ref_group = subset(data, grp == "B"),
.in_ref_col = FALSE,
.df_row = data,
variables = list(arm = "grp", strata = "strata"),
groups_list = groups
))
)
})

testthat::test_that("estimate_odds_ratio estimates right OR and CI (unstratified analysis)", {
Expand All @@ -120,10 +132,14 @@ testthat::test_that("estimate_odds_ratio estimates right OR and CI (stratified a
strata = factor(sample(c("C", "D"), 100, TRUE))
)

result <- basic_table() %>%
split_cols_by(var = "grp", ref_group = "A", split_fun = ref_group_position("first")) %>%
estimate_odds_ratio(vars = "rsp", variables = list(arm = "grp", strata = "strata")) %>%
build_table(df = data)
# https://github.com/therneau/survival/issues/240
withr::with_options(
opts_partial_match_old,
result <- basic_table() %>%
split_cols_by(var = "grp", ref_group = "A", split_fun = ref_group_position("first")) %>%
estimate_odds_ratio(vars = "rsp", variables = list(arm = "grp", strata = "strata")) %>%
build_table(df = data)
)

res <- testthat::expect_silent(result)
testthat::expect_snapshot(res)
Expand Down Expand Up @@ -154,7 +170,11 @@ testthat::test_that("estimate_odds_ratio works with strata and combined groups",
groups_list = groups
)

result <- build_table(lyt = lyt, df = anl)
# https://github.com/therneau/survival/issues/240
withr::with_options(
opts_partial_match_old,
result <- build_table(lyt = lyt, df = anl)
)

res <- testthat::expect_silent(result)
testthat::expect_snapshot(res)
Expand All @@ -172,14 +192,18 @@ testthat::test_that("s_odds_ratio method argument works", {
stringsAsFactors = TRUE
)

res <- s_odds_ratio(
df = subset(dta, grp == "A"),
.var = "rsp",
.ref_group = subset(dta, grp == "B"),
.in_ref_col = FALSE,
.df_row = dta,
variables = list(arm = "grp", strata = "strata"),
method = "approximate"
# https://github.com/therneau/survival/issues/240
withr::with_options(
opts_partial_match_old,
res <- s_odds_ratio(
df = subset(dta, grp == "A"),
.var = "rsp",
.ref_group = subset(dta, grp == "B"),
.in_ref_col = FALSE,
.df_row = dta,
variables = list(arm = "grp", strata = "strata"),
method = "approximate"
)
)

testthat::expect_false(all(is.na(res$or_ci)))
Expand Down Expand Up @@ -213,7 +237,11 @@ testthat::test_that("estimate_odds_ratio method argument works", {
split_cols_by(var = "grp", ref_group = "B") %>%
estimate_odds_ratio(vars = "rsp", variables = list(arm = "grp", strata = "strata"), method = "approximate")

result <- build_table(lyt, df = dta)
# https://github.com/therneau/survival/issues/240
withr::with_options(
opts_partial_match_old,
result <- build_table(lyt, df = dta)
)

res <- testthat::expect_silent(result)
testthat::expect_snapshot(res)
Expand Down

0 comments on commit 9b4b80f

Please sign in to comment.