Skip to content

Commit

Permalink
better message
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Jun 27, 2024
1 parent 6ecb054 commit d1c2627
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
19 changes: 13 additions & 6 deletions R/demean.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
#' is required, see [`center()`]. See [`performance::check_heterogeneity_bias()`]
#' to check for heterogeneity bias.
#'
#' @note
#' Variables specified in `by` or `select` that could not be found in the data
#' arte ignored. A message is printed, indicating the variables that were not
#' found.
#'
#' @section Heterogeneity Bias:
#'
#' Mixed models include different levels of sources of variability, i.e.
Expand Down Expand Up @@ -318,12 +323,14 @@ degroup <- function(x,

if (length(not_found) && isTRUE(verbose)) {
insight::format_alert(
sprintf(
"%i variable%s not found in the dataset: %s\n",
length(not_found),
ifelse(length(not_found) > 1, "s were", " was"),
toString(not_found)
)
paste0(
"Variable",
ifelse(length(not_found) > 1, "s ", " "),
text_concatenate(not_found, enclose = "\""),
ifelse(length(not_found) > 1, " were", " was"),
" not found in the dataset."
),
.misspelled_string(colnames(x), not_found, "Possibly misspelled or not yet defined?")
)
}

Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-demean.R
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ test_that("demean, sanity checks", {
by = c("e42dep", "c172code"),
suffix_demean = "_within"
),
regex = "1 variable was not found"
regex = "Variable \"neg_c_8\" was not found"
)
expect_message(
degroup(
Expand All @@ -180,6 +180,6 @@ test_that("demean, sanity checks", {
by = c("e42dep", "c173code"),
suffix_demean = "_within"
),
regex = "2 variables were not found"
regex = "Variables \"neg_c_8\" and \"c173code\" were not found"
)
})
})

0 comments on commit d1c2627

Please sign in to comment.