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

Tidyverse consistency #246

Open
hadley opened this issue Dec 2, 2021 · 1 comment
Open

Tidyverse consistency #246

hadley opened this issue Dec 2, 2021 · 1 comment
Labels
feature a feature request or enhancement

Comments

@hadley
Copy link
Member

hadley commented Dec 2, 2021

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 hadley changed the title Vectorisation consistency Tidyverse consistency Dec 6, 2021
@hadley hadley added the feature a feature request or enhancement label Jan 25, 2023
jennybc added a commit that referenced this issue Sep 22, 2023
This is different from what's planned for `glue_data()` / `glue()` in #246, but I think it's what we want.

In any case, it preserves existing behaviour. If we want something else, it would need to happen in #246, possibly as part of an edition.
jennybc added a commit that referenced this issue Sep 22, 2023
* Refine `+` method

* Add a test

* Update tests/testthat/test-glue.R

Co-authored-by: Hadley Wickham <h.wickham@gmail.com>

* Add a test for `+`ing size incompatible inputs

* Tidy up these tests

* Treat `NULL` like `character()` in `+`

This is different from what's planned for `glue_data()` / `glue()` in #246, but I think it's what we want.

In any case, it preserves existing behaviour. If we want something else, it would need to happen in #246, possibly as part of an edition.

* Tweak NEWS

---------

Co-authored-by: Hadley Wickham <h.wickham@gmail.com>
@jennybc
Copy link
Member

jennybc commented Sep 22, 2023

Consult tidyverse/design#24 when tackling this

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

No branches or pull requests

2 participants