Skip to content

Commit

Permalink
add_ci() fix (#1490)
Browse files Browse the repository at this point in the history
* fix

* Update add_ci.md

* snap updates

* update

* Update test-add_global_p.R

* increment version number
  • Loading branch information
ddsjoberg authored Apr 13, 2023
1 parent 741f93b commit 287f6b1
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: gtsummary
Title: Presentation-Ready Data Summary and Analytic Result
Tables
Version: 1.7.0.9006
Version: 1.7.0.9007
Authors@R:
c(person(given = "Daniel D.",
family = "Sjoberg",
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# gtsummary (development version)

* Bug fix when a subset of CIs are requested in `add_ci(include=)`. (#1484)

* Added French translations for new marginal effects tidiers housed in {broom.helpers}. (#1417)

* Added theme elements to control the default headers in `tbl_svysummary()`. (#1452)
Expand Down
6 changes: 3 additions & 3 deletions R/add_ci.R
Original file line number Diff line number Diff line change
Expand Up @@ -262,21 +262,21 @@ add_ci.tbl_summary <- function(x,
if (inherits(x, "tbl_summary")) {
single_ci_fn <- single_ci
}
if (inherits(x, "tbl_svysummary")) {
else if (inherits(x, "tbl_svysummary")) {
single_ci_fn <- single_ci_svy
}
x <-
x %>%
add_stat(
fns = everything() ~ purrr::partial(single_ci_fn,
fns = all_of(include) ~ purrr::partial(single_ci_fn,
method = method,
conf.level = conf.level,
statistic = statistic,
style_fun = style_fun,
summary_type = summary_type,
df = df
),
location = list(everything() ~ "label", all_categorical(FALSE) ~ "level")
location = list(all_of(include) ~ "label", all_categorical(FALSE) ~ "level")
) %>%
# moving the CI cols to after the original stat cols (when `by=` variable present)
# also renaming CI columns
Expand Down
16 changes: 16 additions & 0 deletions tests/testthat/_snaps/add_ci.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,22 @@
</table>
</div>

# add_ci() works on a subset of variables

Code
trial %>% tbl_summary(include = c(response, age)) %>% add_ci(include = age) %>%
as_tibble()
Message
x `add_ci()` added mean CI for "age"; however, no mean is shown in the `tbl_summary()` table.
Output
# A tibble: 4 x 3
`**Characteristic**` `**N = 200**` `**95% CI**`
<chr> <chr> <chr>
1 Tumor Response 61 (32%) <NA>
2 Unknown 7 <NA>
3 Age 47 (38, 57) 45, 49
4 Unknown 11 <NA>

# add_ci() works with tbl_svysummary

Code
Expand Down
11 changes: 11 additions & 0 deletions tests/testthat/test-add_ci.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ test_that("add_ci() works", {
expect_snapshot()
})

test_that("add_ci() works on a subset of variables", {
expect_snapshot(
trial %>%
tbl_summary(
include = c(response, age)
) %>%
add_ci(include = age) %>%
as_tibble()
)
})

test_that("add_ci() throws errors with bad arguments", {
tbl0 <-
trial %>%
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-add_global_p.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ test_that("no errors/warnings with standard use after tbl_regression with non-st
tbl1 <- tbl_regression(mod1)
tbl2 <- tbl_regression(mod2)

expect_snapshot(res %>% render_as_html())
expect_equal(
car::Anova(mod1, type = "II") %>% select(last_col()) %>% pull() %>% discard(is.na),
tbl1 %>% add_global_p(include = everything(), type = "II") %>% pluck("table_body", "p.value") %>% discard(is.na)
Expand Down

0 comments on commit 287f6b1

Please sign in to comment.