Skip to content

Commit

Permalink
error msg update
Browse files Browse the repository at this point in the history
  • Loading branch information
ddsjoberg committed Jul 4, 2024
1 parent 2452395 commit 19d801d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
21 changes: 16 additions & 5 deletions R/ard_dichotomous.survey.design.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,23 @@ ard_dichotomous.survey.design <- function(data,
accepted_values <- .unique_and_sorted(data[[column]])
if (length(value) != 1L || !value %in% accepted_values) {
message <- "Error in argument {.arg value} for variable {.val {column}}."
message <-
case_switch(
length(value) != 1L ~ c(message, "i" = "The value must be one of {.val {accepted_values}}."),
.default = c(message, "i" = "A value of {.val {value}} was passed, but must be one of {.val {accepted_values}}.")
)
if (length(value) == 1L) {
message <-
case_switch(
inherits(data[[column]], "factor") ~
c(message, i = "To summarize this value, use {.fun forcats::fct_expand} to add {.val {value}} as a level."),
.default = c(message, i = "To summarize this value, make the column a factor and include {.val {value}} as a level.")
)
}


cli::cli_abort(
if (length(value) != 1L) {
c(message, "i" = "The value must be one of {.val {accepted_values}}.")
} else {
c(message, "i" = "A value of {.val {value}} was passed, but must be one of {.val {accepted_values}}.")
},
message = message,
call = get_cli_abort_call()
)
}
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/_snaps/ard_dichotomous.survey.design.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Error in `ard_dichotomous()`:
! Error in argument `value` for variable "cyl".
i A value of 4 was passed, but must be one of TRUE and FALSE.
i To summarize this value, make the column a factor and include 4 as a level.

---

Expand All @@ -17,6 +18,7 @@
Error in `ard_dichotomous()`:
! Error in argument `value` for variable "vs".
i A value of 4 was passed, but must be one of 0 and 1.
i To summarize this value, use `forcats::fct_expand()` to add 4 as a level.

---

Expand All @@ -27,4 +29,5 @@
Error in `ard_dichotomous()`:
! Error in argument `value` for variable "disp".
i A value of "turn" was passed, but must be one of 71.1, 75.7, 78.7, 79, 95.1, 108, 120.1, 120.3, 121, 140.8, 145, 146.7, 160, 167.6, 225, 258, 275.8, 301, ..., 460, and 472.
i To summarize this value, make the column a factor and include "turn" as a level.

0 comments on commit 19d801d

Please sign in to comment.