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

Refine + method #309

Merged
merged 7 commits into from
Sep 22, 2023
Merged

Refine + method #309

merged 7 commits into from
Sep 22, 2023

Conversation

jennybc
Copy link
Member

@jennybc jennybc commented Sep 21, 2023

I merged #297, but then I got to thinking more about recycling. That PR actually changed some behaviour around length-0 input (#286 (comment)).

I think we'll be happier in the long-run to route + through glue_data() rather than paste0() to keep recycling behaviour more in sync. I might add a couple of tests to this PR re: + and input lengths.

@jennybc jennybc requested a review from hadley September 21, 2023 14:37
tests/testthat/test-glue.R Outdated Show resolved Hide resolved
@jennybc
Copy link
Member Author

jennybc commented Sep 21, 2023

What do you think the correct behaviour is for NULL? 🤔

With CRAN glue (v1.6.2), it's treated like character():

str(glue::as_glue("hello") + NULL)
#>  'glue' chr(0)

With anything after 740ca7f, it's an error:

as_glue("hello") + NULL
#> Error in `+.glue`(as_glue("hello"), NULL): RHS must be a character vector.

The tidyverse recycling rules and #246 don't obviously speak to what to do in the + case.

In arithmetic, it is like adding something of the correct type but of length zero:

1.5 + NULL
#> numeric(0)

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
Copy link
Member Author

jennybc commented Sep 22, 2023

I decided to make glue + NULL return character(). That's was it's been doing and it's consistent with "normal" addition.

@jennybc jennybc merged commit 42d29d4 into main Sep 22, 2023
12 checks passed
@hadley
Copy link
Member

hadley commented Sep 25, 2023

I'm not sure that's right; I would have expected it to return glue, because (a) we generally ignore nulls and (b) it makes it more consistent with paste().

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

Successfully merging this pull request may close these issues.

2 participants