glue
glue copied to clipboard
Tidyverse consistency
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 likecharacter()
)
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.
Consult https://github.com/tidyverse/design/issues/24 when tackling this