Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ddsjoberg committed Jul 8, 2024
1 parent b30c138 commit 2375ee1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion R/ard_categorical.survey.design.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ ard_categorical.survey.design <- function(data,
# return note about column names that result in errors -----------------------
if (any(by %in% c("variable", "variable_level"))) {
cli::cli_abort(
"The {.arg by} argument cannot include variables named {.val {c('variable', 'variable_level')}}",
"The {.arg by} argument cannot include variables named {.val {c('variable', 'variable_level')}}.",
call = get_cli_abort_call()
)
}
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/ard_categorical.survey.design.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
# ard_categorical.survey.design(by) messages about protected names

Code
ard_categorical(svy_trial, by = variable, variables = gear)
ard_categorical(svy_mtcars, by = variable, variables = gear)
Condition
Error in `ard_categorical()`:
! The `by` argument cannot include variables named "variable" and "variable_level"
! The `by` argument cannot include variables named "variable" and "variable_level".

17 changes: 14 additions & 3 deletions tests/testthat/test-ard_categorical.survey.design.R
Original file line number Diff line number Diff line change
Expand Up @@ -1175,15 +1175,26 @@ test_that("ard_categorical.survey.design() works with variables with only 1 leve


test_that("ard_categorical.survey.design(by) messages about protected names", {
svy_trial <-
svy_mtcars <-
survey::svydesign(
ids = ~1,
data = mtcars |> dplyr::mutate(variable = am, variable_level = cyl),
data = mtcars |>
dplyr::mutate(
variable = am,
variable_level = cyl,
by = am,
by_level = cyl
),
weights = ~1
)

expect_snapshot(
error = TRUE,
ard_categorical(svy_trial, by = variable, variables = gear)
ard_categorical(svy_mtcars, by = variable, variables = gear)
)

expect_error(
ard_categorical(svy_mtcars, by = variable_level, variables = gear),
'The `by` argument cannot include variables named "variable" and "variable_level".'
)
})

0 comments on commit 2375ee1

Please sign in to comment.