-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
switch check_type() to use cli package #1235
Changes from 3 commits
4c5b7f1
f2fd46a
8d3897e
d962daa
9106ffd
0a36bb7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -436,13 +436,36 @@ check_type <- function(dat, quant = TRUE, types = NULL, call = caller_env()) { | |
} | ||
|
||
if (!all(all_good)) { | ||
rlang::abort( | ||
paste0( | ||
"All columns selected for the step", | ||
" should be ", | ||
label, | ||
"." | ||
), | ||
info <- get_types(dat)[!all_good, ] | ||
classes <- map_chr(info$type, function(x) x[1]) | ||
counts <- vctrs::vec_split(info$variable, classes) | ||
counts$count <- lengths(counts$val) | ||
counts$text_len <- cli::console_width() - 19 - (counts$count > 1) - | ||
nchar(counts$key) | ||
|
||
# cli::ansi_collapse() doesn't work for length(x) == 1 | ||
# https://github.com/r-lib/cli/issues/590 | ||
variable_collapse <- function(x, width) { | ||
x <- paste0("{.var ", x, "}") | ||
if (length(x) == 1) { | ||
res <- cli::ansi_strtrim(x, width = width) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in the unlikely event that the single variable name is too large, i used |
||
} else { | ||
res <- cli::ansi_collapse(x, width = width, style = "head") | ||
} | ||
res | ||
} | ||
|
||
problems <- glue::glue_data( | ||
counts, | ||
"{count} {key} variable{ifelse(count == 1, '', 's')} \\ | ||
found: {purrr::map2_chr(val, text_len, variable_collapse)}" | ||
simonpcouch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
names(problems) <- rep("*", length(problems)) | ||
|
||
message <- "All columns selected for the step should be {label}." | ||
EmilHvitfeldt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
cli::cli_abort( | ||
c("x" = message, problems), | ||
call = call | ||
) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,8 @@ | |
Condition | ||
Error in `step_ratio()`: | ||
Caused by error in `prep()`: | ||
! All columns selected for the step should be double, or integer. | ||
x All columns selected for the step should be double, or integer. | ||
* 1 factor variable found: `x5` | ||
|
||
--- | ||
|
||
|
@@ -14,7 +15,8 @@ | |
Condition | ||
Error in `step_ratio()`: | ||
Caused by error in `prep()`: | ||
! All columns selected for the step should be double, or integer. | ||
x All columns selected for the step should be double, or integer. | ||
* 1 factor variable found: `x5` | ||
|
||
--- | ||
|
||
|
@@ -23,7 +25,8 @@ | |
Condition | ||
Error in `step_ratio()`: | ||
Caused by error in `prep()`: | ||
! All columns selected for the step should be double, or integer. | ||
x All columns selected for the step should be double, or integer. | ||
* 8 factor variables found: `x5`, `x5`, `x5`, `x5`, ... | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's happening here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. solved with a call to |
||
|
||
# check_name() is used | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-19
- my count of the length of "• variable found: "(counts$count > 1)
- whether variable has ans
or notnchar(counts$key)
- length of the variable type