Use `cli::format_bullets_raw()` for indented bullets in `vec_as_names(repair = "check_unique")` error
From https://github.com/tidyverse/tidyr/pull/1448/files#diff-49b66fa13a6cdea8a775f51443a0356faf5b99be884c430fd0a37e956ad5494eR180-R185
bullets <- map2_chr(inners, outers, function(inner, outer) {
cli::format_inline("{.code {inner}}, within {.code {outer}}.")
})
bullets <- set_names(bullets, "i")
bullets <- cli::format_bullets_raw(bullets)
bullets <- set_names(bullets, " ")
To improve on the * we use here
vctrs::vec_as_names(c("x", "x"), repair = "check_unique")
#> Error:
#> ! Names must be unique.
#> ✖ These names are duplicated:
#> * "x" at locations 1 and 2.
Created on 2023-01-09 with reprex v2.0.2.9000
@gaborcsardi Could cli be extended to support tree-lists of character vectors to create nested bullets?
I guess the message in that tidyr case could look like this?
message <- list(
"Can't duplicate names within the affected columns.",
"x" = "These names are duplicated:",
" " = list("i" = "`x` within `y` and `z`."),
" " = list("i" = "`a` within `y` and `w`."),
"i" = "Use `names_sep` to disambiguate using the column name.",
"i" = "Or use `names_repair` to specify a repair strategy."
)
I would rather support a single markdown template. Much easier to write, we already know it and it works for other things as well. E.g.
message <- "
Can't duplicate names within the affected columns.
- x These names are duplicated:
- i {.var x} within {.var y} and {.var z}.
- i {.var a} within {.var y} and {.var w}.
- i Use {.arg names_sep} to disambiguate using the column name.
- i Or use {.arg names_repair} to specify a repair strategy."
This would be nice too, but I think the named list/character vector UI is easier to program with.
Ideally you would not create strings programmatically, because that is hard to translate. cli will have vectorization, and my goal is to have templates that are expressive enough, so that you can write a single template.
This said, sure, if you want you can open an issue for having another level of lists, it is probably pretty easy to implement. 😄
That's interesting. One advantage of having the list UI is that we can start using it right away, and then it will be easy to identify use cases for the templating approach, see what's needed, the limitations, etc. On the other hand we can use Davis' raw bullets workaround for this.