Skip to content
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

cli_vec: vec-trunc not working #652

Closed
lgaborini opened this issue Nov 24, 2023 · 4 comments
Closed

cli_vec: vec-trunc not working #652

lgaborini opened this issue Nov 24, 2023 · 4 comments

Comments

@lgaborini
Copy link

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
Copy link
Author

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

@DanChaltiel
Copy link
Contributor

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 :-)

@lgaborini lgaborini reopened this Feb 27, 2024
@DanChaltiel
Copy link
Contributor

Digging in the code, I found that "vec-trunc" is used in inline_collapse(), which will eventually call ansi_collapse().

The current issue is documented (although not justified) in ?ansi_collapse:

trunc Maximum number of elements to show. For style = "head" at least trunc = 1 is used. For style = "both-ends" at least trunc = 5 is used, even if a smaller number is specified.

I guess this limit was set to ensure readability, but I don't understand why not let the user decide what is readable or not...
For instance, in my case, readability is less important than console cluttering, so a limit of 3 or even 2 would have been a very good thing.

Alternatively, you can use "vec-trunc-style" to force the "head" truncation style:

nms <- cli_vec(names(mtcars), list("vec_trunc"=2, "vec-trunc-style"="head"))
cli_text("Column names: {nms}.")

I guess this will be fixed when they update the documentation of ?cli_vec

@gaborcsardi
Copy link
Member

See vec-trunc-style at https://cli.r-lib.org/reference/themes.html?q=vec-trunc#supported-properties

library(cli)
x <- cli_vec(names(mtcars), list("vec-trunc" = 3, "vec-trunc-style" = "head"))
cli_text("Column names: {x}.")
Column names: mpg, cyl, disp, ….

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants