Skip to content

Commit

Permalink
no comma for 2 item list
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilHvitfeldt committed Oct 11, 2023
1 parent d962daa commit 9106ffd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions R/misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -439,17 +439,23 @@ check_type <- function(dat, quant = TRUE, types = NULL, call = caller_env()) {
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)
counts$text_len <- cli::console_width() - 18 - (counts$count > 1) -
nchar(counts$key) - (counts$count > 2)

# 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)
} else if (length(x) == 2) {
res <- cli::ansi_collapse(
x, last = " and ", width = width, style = "head"
)
} else {
res <- cli::ansi_collapse(x, width = width, style = "head")
res <- cli::ansi_collapse(
x, width = width, style = "head"
)
}
res
}
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/factor2string.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Error in `step_factor2string()`:
Caused by error in `prep()`:
x All columns selected for the step should be factor or ordered.
* 2 string variables found: `w`, and `x`
* 2 string variables found: `w` and `x`

# empty printing

Expand Down

0 comments on commit 9106ffd

Please sign in to comment.