Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
edelarua committed Oct 7, 2024
1 parent 6c1d58a commit aa58555
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions R/odds_ratio.R
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ s_odds_ratio <- function(df,
}
}

if (is.na(y$or_ci$est)) {
message(
if ("est" %in% names(y$or_ci) && is.na(y$or_ci[["est"]]) && method != "approximate") {
warning(
"Unable to compute the odds ratio estimate. Please try re-running the function with ",
'parameter `method` set to "approximate".'
)
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test-odds_ratio.R
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ testthat::test_that("estimate_odds_ratio works with strata and combined groups",
})

testthat::test_that("s_odds_ratio method argument works", {
set.seed(1)
nex <- 2000 # Number of example rows
dta <- data.frame(
"rsp" = sample(c(TRUE, FALSE), nex, TRUE),
Expand All @@ -182,6 +183,18 @@ testthat::test_that("s_odds_ratio method argument works", {
)

testthat::expect_false(all(is.na(res$or_ci)))

# warning works
expect_warning(
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")
)
)
})

testthat::test_that("estimate_odds_ratio method argument works", {
Expand Down

0 comments on commit aa58555

Please sign in to comment.