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

Closes #116 Check for other package messaging in our snapshots #125

Merged
merged 6 commits into from
Apr 25, 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
23 changes: 4 additions & 19 deletions tests/testthat/_snaps/ard_car_vif.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,12 @@
1 BMIBL car_vif VIF VIF 1.010522 1 NULL NULL
2 EDUCLVL car_vif VIF VIF 1.010522 1 NULL NULL

# ard_car_vif() appropriate errors are given for model with only 1 term

Code
as.data.frame(ard_car_vif(lm(AGE ~ ARM, data = cards::ADSL)))
Output
variable context stat_name stat_label stat fmt_fn warning
1 ARM car_vif VIF VIF NULL NULL NULL
2 ARM car_vif GVIF GVIF NULL NULL NULL
3 ARM car_vif aGVIF Adjusted GVIF NULL NULL NULL
4 ARM car_vif df df NULL NULL NULL
error
1 model contains fewer than 2 terms
2 model contains fewer than 2 terms
3 model contains fewer than 2 terms
4 model contains fewer than 2 terms

# ard_vif() issues friendly messaging for incorrect object passed in/can't get terms of model

Code
ard_vif(cards::ADSL)
ard_car_vif(cards::ADSL)
Condition
Error in `ard_vif()`:
! could not find function "ard_vif"
Error in `ard_car_vif()`:
! There was an error running `car::vif()`. See below.
x no applicable method for 'vcov' applied to an object of class "c('tbl_df', 'tbl', 'data.frame')"

33 changes: 0 additions & 33 deletions tests/testthat/_snaps/ard_effectsize_cohens_d.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
# ard_effectsize_cohens_d() works

Code
as.data.frame(dplyr::select(ard_effectsize_cohens_d(cards::ADSL, by = ARM,
variables = AGE), c("variable", "stat_name", "error")))
Output
variable stat_name error
1 AGE estimate Grouping variable y must have exactly 2 levels.
2 AGE conf.level Grouping variable y must have exactly 2 levels.
3 AGE conf.low Grouping variable y must have exactly 2 levels.
4 AGE conf.high Grouping variable y must have exactly 2 levels.
5 AGE mu Grouping variable y must have exactly 2 levels.
6 AGE paired Grouping variable y must have exactly 2 levels.
7 AGE pooled_sd Grouping variable y must have exactly 2 levels.
8 AGE alternative Grouping variable y must have exactly 2 levels.

---

Code
as.data.frame(dplyr::slice_head(dplyr::group_by(dplyr::select(
ard_effectsize_cohens_d(dplyr::filter(cards::ADSL, ARM %in% c("Placebo",
Expand All @@ -30,20 +14,3 @@
5 ARM HEIGHTBL effectsize_cohens_d CI Confidence Level 0.95
6 ARM HEIGHTBL effectsize_cohens_d CI Lower Bound -0.600975

# ard_effectsize_paired_cohens_d() works

Code
as.data.frame(dplyr::select(ard_effectsize_paired_cohens_d(dplyr::mutate(
ADSL_paired, ARM = ifelse(dplyr::row_number() == 1L, "3rd ARM", ARM)), by = ARM,
variable = AGE, id = USUBJID), c("variable", "stat_name", "error")))
Output
variable stat_name error
1 AGE estimate The `by` argument must have two and only two levels.
2 AGE conf.level The `by` argument must have two and only two levels.
3 AGE conf.low The `by` argument must have two and only two levels.
4 AGE conf.high The `by` argument must have two and only two levels.
5 AGE mu The `by` argument must have two and only two levels.
6 AGE paired The `by` argument must have two and only two levels.
7 AGE pooled_sd The `by` argument must have two and only two levels.
8 AGE alternative The `by` argument must have two and only two levels.

33 changes: 0 additions & 33 deletions tests/testthat/_snaps/ard_effectsize_hedges_g.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
# ard_effectsize_hedges_g() works

Code
as.data.frame(dplyr::select(ard_effectsize_hedges_g(cards::ADSL, by = ARM,
variable = AGE), c("variable", "stat_name", "error")))
Output
variable stat_name error
1 AGE estimate Grouping variable y must have exactly 2 levels.
2 AGE conf.level Grouping variable y must have exactly 2 levels.
3 AGE conf.low Grouping variable y must have exactly 2 levels.
4 AGE conf.high Grouping variable y must have exactly 2 levels.
5 AGE mu Grouping variable y must have exactly 2 levels.
6 AGE paired Grouping variable y must have exactly 2 levels.
7 AGE pooled_sd Grouping variable y must have exactly 2 levels.
8 AGE alternative Grouping variable y must have exactly 2 levels.

---

Code
as.data.frame(dplyr::slice_head(dplyr::group_by(dplyr::select(
ard_effectsize_hedges_g(dplyr::filter(cards::ADSL, ARM %in% c("Placebo",
Expand All @@ -30,20 +14,3 @@
5 ARM HEIGHTBL effectsize_hedges_g CI Confidence Level 0.95
6 ARM HEIGHTBL effectsize_hedges_g CI Lower Bound -0.5982873

# ard_effectsize_paired_hedges_g() works

Code
as.data.frame(dplyr::select(ard_effectsize_paired_hedges_g(dplyr::mutate(
ADSL_paired, ARM = ifelse(dplyr::row_number() == 1L, "3rd ARM", ARM)), by = ARM,
variable = AGE, id = USUBJID), c("variable", "stat_name", "error")))
Output
variable stat_name error
1 AGE estimate The `by` argument must have two and only two levels.
2 AGE conf.level The `by` argument must have two and only two levels.
3 AGE conf.low The `by` argument must have two and only two levels.
4 AGE conf.high The `by` argument must have two and only two levels.
5 AGE mu The `by` argument must have two and only two levels.
6 AGE paired The `by` argument must have two and only two levels.
7 AGE pooled_sd The `by` argument must have two and only two levels.
8 AGE alternative The `by` argument must have two and only two levels.

75 changes: 0 additions & 75 deletions tests/testthat/_snaps/ard_stats_t_test.md

This file was deleted.

14 changes: 4 additions & 10 deletions tests/testthat/test-ard_car_vif.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,19 @@ test_that("ard_car_vif() works", {
})

test_that("ard_car_vif() appropriate errors are given for model with only 1 term", {
expect_snapshot(
lm(AGE ~ ARM, data = cards::ADSL) |>
ard_car_vif() |>
as.data.frame()
)
expect_equal(
lm(AGE ~ ARM, data = cards::ADSL) |>
ard_car_vif() |>
dplyr::select(error) |>
unlist() |>
unique(),
"model contains fewer than 2 terms"
dplyr::select(error) %>%
is.null(),
FALSE
)
})


test_that("ard_vif() issues friendly messaging for incorrect object passed in/can't get terms of model", {
expect_snapshot(
error = TRUE,
cards::ADSL |> ard_vif()
cards::ADSL |> ard_car_vif()
)
})
14 changes: 8 additions & 6 deletions tests/testthat/test-ard_effectsize_cohens_d.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ test_that("ard_effectsize_cohens_d() works", {
)

# errors are properly handled
expect_snapshot(
expect_equal(
cards::ADSL |>
ard_effectsize_cohens_d(by = ARM, variables = AGE) |>
dplyr::select(c("variable", "stat_name", "error")) |>
as.data.frame()
dplyr::select(error) %>%
is.null(),
FALSE
)

# test that the function works with multiple variables
Expand Down Expand Up @@ -83,13 +84,14 @@ test_that("ard_effectsize_paired_cohens_d() works", {
)

# errors are properly handled
expect_snapshot(
expect_equal(
ADSL_paired |>
dplyr::mutate(
ARM = ifelse(dplyr::row_number() == 1L, "3rd ARM", ARM)
) |>
ard_effectsize_paired_cohens_d(by = ARM, variable = AGE, id = USUBJID) |>
dplyr::select(c("variable", "stat_name", "error")) |>
as.data.frame()
dplyr::select(error) %>%
is.null(),
FALSE
)
})
14 changes: 8 additions & 6 deletions tests/testthat/test-ard_effectsize_hedges_g.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ test_that("ard_effectsize_hedges_g() works", {
)

# errors are properly handled
expect_snapshot(
expect_equal(
cards::ADSL |>
ard_effectsize_hedges_g(by = ARM, variable = AGE) |>
dplyr::select(c("variable", "stat_name", "error")) |>
as.data.frame()
dplyr::select(error) %>%
is.null(),
FALSE
)

# test that the function works with multiple variables as once
Expand Down Expand Up @@ -83,13 +84,14 @@ test_that("ard_effectsize_paired_hedges_g() works", {
)

# errors are properly handled
expect_snapshot(
expect_equal(
ADSL_paired |>
dplyr::mutate(
ARM = ifelse(dplyr::row_number() == 1L, "3rd ARM", ARM)
) |>
ard_effectsize_paired_hedges_g(by = ARM, variable = AGE, id = USUBJID) |>
dplyr::select(c("variable", "stat_name", "error")) |>
as.data.frame()
dplyr::select(error) %>%
is.null(),
FALSE
)
})
12 changes: 8 additions & 4 deletions tests/testthat/test-ard_stats_t_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ test_that("ard_stats_t_test() works", {
)

# errors are properly handled
expect_snapshot(
expect_equal(
cards::ADSL |>
ard_stats_t_test(by = ARM, variable = AGE, var.equal = TRUE) |>
as.data.frame()
dplyr::select(error) %>%
is.null(),
FALSE
)

# test that the function works with multiple variables at once
Expand Down Expand Up @@ -102,12 +104,14 @@ test_that("ard_stats_paired_t_test() works", {
)

# errors are properly handled
expect_snapshot(
expect_equal(
ADSL_paired |>
dplyr::mutate(
ARM = ifelse(dplyr::row_number() == 1L, "3rd ARM", ARM)
) |>
ard_stats_paired_t_test(by = ARM, variable = AGE, id = USUBJID, var.equal = TRUE) |>
as.data.frame()
dplyr::select(error) %>%
is.null(),
FALSE
)
})
Loading