Skip to content

Commit

Permalink
warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
larmarange committed Jan 6, 2025
1 parent 4180319 commit bd2953b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
2 changes: 1 addition & 1 deletion R/lookfor.R
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ print.look_for <- function(x, ...) {

print.data.frame(x, row.names = FALSE, quote = FALSE, right = FALSE)
} else if (nrow(x) == 0) {
message("Nothing found. Sorry.")
cli::cli_alert_warning("Nothing found. Sorry.")
} else {
print(dplyr::as_tibble(x))
}
Expand Down
8 changes: 4 additions & 4 deletions R/recode.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ recode.haven_labelled <- function(
} else {
var_label(ret) <- var_label(.x)
if (.keep_value_labels || .combine_value_labels) {
warning(
"The type of .x has been changed and value labels attributes",
"have been lost."
)
cli::cli_warn(paste(
"The type of {.arg .x} ({mode(ret)}) has been changed",
"and value labels have been lost."
))
}
}
ret
Expand Down
14 changes: 5 additions & 9 deletions R/recode_if.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,11 @@ recode_if <- function(x, condition, true) {
x[condition] <- true[condition]
}

if (!identical(class(x), original_class)) {
warning(
"Class of 'x' has changed and is now equal to \"",
paste(class(x), collapse = ", "),
"\".\n",
"This is usually the case when class of 'value' is different from `x`\n.",
"and forced R to coerce 'x' to the class of 'value'."
)
}
if (!identical(class(x), original_class))
cli::cli_warn(paste(
"Class of {.arg x} (originally {.field {original_class}}) has changed",
"and was coerced to {.field {class(x)}}."
))

x
}
4 changes: 2 additions & 2 deletions R/to_labelled.R
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ to_labelled.factor <- function(x, labels = NULL, .quiet = FALSE, ...) {
all(!is.na(l$code)) &&
all(!is.na(l$code))
) {
warning("'x' looks prefixed, but duplicated codes found.")
cli::cli_warn("{.arg x} looks prefixed, but duplicated codes found.")
}
# normal case
labs <- seq_along(levels(x))
Expand All @@ -259,7 +259,7 @@ to_labelled.factor <- function(x, labels = NULL, .quiet = FALSE, ...) {
# "[code] label" case
num_l <- suppressWarnings(as.numeric(l$code))
if (!.quiet && all(!is.na(num_l)) && any(duplicated(num_l))) {
warning("All codes seem numeric but some duplicates found.")
cli::cli_warn("All codes seem numeric but some duplicates found.")
}
if (all(!is.na(num_l)) && !any(duplicated(num_l))) {
l$code <- as.numeric(l$code)
Expand Down

0 comments on commit bd2953b

Please sign in to comment.