glue icon indicating copy to clipboard operation
glue copied to clipboard

Tidyverse consistency

Open hadley opened this issue 2 years ago • 1 comments

library(stringr)

str_c(1:2, "-", character())
#> Error in `stop_vctrs()`: Can't recycle `..1` (size 2) to match `..3` (size 0).
str_glue("{x}-{y}", x = 1:2, y = character())

str_c("-", c(1, NA), "-")
#> [1] "-1-" NA
str_glue("-{x}-", x = c(1, NA))
#> -1-
#> -NA-

str_c("-", NULL, "-")
#> [1] "--"
str_glue("-{x}-", x = NULL)

Created on 2021-12-06 by the reprex package (v2.0.1)

Three problems:

  • Need to error if vector lengths are inconsistent
  • NA should be infectious
  • NULL should be silently dropped (not treated like character())

The last two can already be control via arguments:

library(stringr)
str_glue("-{x}-", x = c(1, NA), .na = NULL)
#> -1-
#> NA
str_c("-", NULL, "-", .null = NULL)
#> [1] "--"

Created on 2021-12-06 by the reprex package (v2.0.1)

But I think it would be good to consider a path forward to bring the defaults into alignment with the rest of the tidyverse, even if it has to go via some sort of edition.

hadley avatar Dec 02 '21 14:12 hadley

Consult https://github.com/tidyverse/design/issues/24 when tackling this

jennybc avatar Sep 22 '23 22:09 jennybc