Skip to content

Commit

Permalink
fix bhhi_format_crosstab() bug
Browse files Browse the repository at this point in the history
  • Loading branch information
eveyp committed Jun 26, 2024
1 parent 6a023ec commit 2878fd0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: bhhitools
Type: Package
Title: Tools For BHHI R Users
Version: 0.6.0
Version: 0.6.1
Authors@R: person("Eve", "Perry", email = "eve.perry@ucsf.edu", role = c("aut", "cre"))
Description: A collection of functions to make R work at BHHI easier.
Encoding: UTF-8
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# bhhitools 0.6.1

* Fixed bug with `bhhi_gt_crosstab()` and `bhhi_format_crosstab()` when the row variable name ended with "_" and 2-4 other characters.

# bhhitools 0.6.0

* Auto-convert variables with Stata value labels from [haven::labelled] to factors in `bhhi_crosstab()` and `bhhi_gt_crosstab()`.
Expand Down
6 changes: 5 additions & 1 deletion R/bhhi_format_crosstab.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ detect_ci <- function(.data) {
}

get_column_name_stems <- function(.data) {
x <- stringr::str_extract(names(.data), "(.*)_.{2,4}$", group = 1)
column_names = names(.data)
# first column is the row var so remove it
column_names = column_names[2:length(column_names)]

x <- stringr::str_extract(column_names, "(.*)_.{2,4}$", group = 1)

unique(x[!is.na(x)])
}
10 changes: 10 additions & 0 deletions tests/testthat/test-bhhi_format_crosstab.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ test_that("bhhi_format_crosstab with ci works", {
expect_gt_output("bhhi_format_crosstab_ci")
})

test_that("bhhi_format_crosstab with ci & 2-4 letter suffix name works", {
create_test_svy_tbl() |>
srvyr::rename(race_cat = race) |>
srvyr::group_by(race_cat, gender) |>
bhhi_cascade(srvyr::survey_prop(vartype = "ci", proportion = TRUE)) |>
bhhi_reshape_crosstab(race_cat, gender) |>
bhhi_format_crosstab() |>
expect_gt_output("bhhi_format_crosstab_ci")
})

test_that("bhhi_format_crosstab with no vartype works", {
create_test_svy_tbl() |>
srvyr::group_by(race, gender) |>
Expand Down

0 comments on commit 2878fd0

Please sign in to comment.