cli icon indicating copy to clipboard operation
cli copied to clipboard

cli_vec: vec-trunc not working

Open lgaborini opened this issue 2 years ago • 2 comments

With {cli} 3.6.1.
Directly from the examples of cli_vec():

library(cli)

x <- cli_vec(names(mtcars), list("vec-trunc" = 3))
cli_text("Column names: {x}.")
#> Column names: mpg, cyl, disp, …, gear, and carb.

Created on 2023-11-24 with reprex v2.0.2

vec-sep and vec-last are not affected.

lgaborini avatar Nov 24 '23 11:11 lgaborini

Closing, I thought vec-trunc would set the maximum number of visible items.
I should sleep more.

lgaborini avatar Nov 24 '23 11:11 lgaborini

It is supposed to do that, but somehow the minimal amount is now 5, which is not documented and doesn't make much sense IMHO.

library(cli)
for(i in 3:7){
  x <- cli_vec(names(mtcars), list("vec-trunc"=i))
  cli_text("Column names (max={i}): {x}.")
}
#> Column names (max=3): mpg, cyl, disp, ..., gear, and carb.
#> Column names (max=4): mpg, cyl, disp, ..., gear, and carb.
#> Column names (max=5): mpg, cyl, disp, ..., gear, and carb.
#> Column names (max=6): mpg, cyl, disp, hp, ..., gear, and carb.
#> Column names (max=7): mpg, cyl, disp, hp, drat, ..., gear, and carb.

Created on 2024-02-21 with reprex v2.0.2

Moreover, the documentation of ?cli_vec provides only an example of vec-trunc, with no real insight into what it does, though there is a bit more in https://cli.r-lib.org/reference/inline-markup.html#collapsing-inline-vectors.

I think you should reopen your issue :-)

DanChaltiel avatar Feb 21 '24 13:02 DanChaltiel