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

vec-last ignored when only 2 elements are provided #681

Closed
JosiahParry opened this issue Mar 21, 2024 · 3 comments
Closed

vec-last ignored when only 2 elements are provided #681

JosiahParry opened this issue Mar 21, 2024 · 3 comments
Labels
bug an unexpected problem or unintended behavior tidy-dev-day 🤓 Tidyverse Developer Day rstd.io/tidy-dev-day

Comments

@JosiahParry
Copy link

cli_vec() is very helpful when informing uses that they should choose one of a set of values. Using vec-last is great because it allows us to say or {last-item} meaning it is one of the options not all of them. However, when only two elements are provided cli_vec() always says "and".

Can it be fixed such that vec-last is used when the vector length is > 1?

v <- cli::cli_vec(
  c("foo", "bar", "foobar"),
  style = list("vec-last" = ", or ")
)

cli::cli_text("Must be one of: {v}.")
#> Must be one of: foo, bar, or foobar.

v <- cli::cli_vec(
  c("foo", "bar"),
  style = list("vec-last" = " or ")
)

cli::cli_text("Must be one of: {v}.")
#> Must be one of: foo and bar.

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

@a-maldet
Copy link

Hi!
I would also appreciate a fix for this problem. Thanks for the great package and all the work you are putting in.

Kind regards
Adrian

@gaborcsardi gaborcsardi added the bug an unexpected problem or unintended behavior label Jun 20, 2024
@gaborcsardi gaborcsardi added the tidy-dev-day 🤓 Tidyverse Developer Day rstd.io/tidy-dev-day label Jul 17, 2024
@gaborcsardi
Copy link
Member

Fixing this is probably a breaking change.

There is also a workaround already:

v <- cli::cli_vec(
  c("foo", "bar"),
  style = list("vec-last" = " or ", "vec-sep2" = " or ")
)
cli::cli_text("Must be one of: {v}.")
Must be one of: foo or bar.

which is also appropriate if you want Oxford comma:

v <- cli::cli_vec(
  c("foo", "bar"),
  style = list("vec-last" = ", or ", "vec-sep2" = " or ")
)
cli::cli_text("Must be one of: {v}.")

Another workaround is to use the .or class:

v <- c("foo", "bar")
cli::cli_text("Must be one of: {.or {v}}.")
Must be one of: foo or bar.

gaborcsardi added a commit to rundel/cli that referenced this issue Aug 28, 2024
@gaborcsardi
Copy link
Member

Closed by #718.

jennybc added a commit to r-lib/usethis that referenced this issue Nov 22, 2024
jennybc added a commit to r-lib/usethis that referenced this issue Nov 25, 2024
* Get use_vignette() working for qmd

* Another test

* Attempt to get "or" between 2 .vals

Approach taken from r-lib/cli#681 (comment)

* Catch up on the article side

* Add NEWS bullet

* Remove comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior tidy-dev-day 🤓 Tidyverse Developer Day rstd.io/tidy-dev-day
Projects
None yet
Development

No branches or pull requests

3 participants