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

Add explicit handling for length 0 variables in glue #303

Closed
PettyCode opened this issue Apr 17, 2023 · 1 comment
Closed

Add explicit handling for length 0 variables in glue #303

PettyCode opened this issue Apr 17, 2023 · 1 comment

Comments

@PettyCode
Copy link

Currently, the glue function returns character(0) when one of the variables to be evaluated has length 0 and is not NULL. The NULL case is already handled by the .null parameter. However, the behaviour with length 0 objects can be confusing and potentially lead to unintended consequences.

I propose adding a new feature that properly handles length 0 variables in the glue function. This feature should provide a clear and consistent behaviour for dealing with length 0 objects, making it easier for users to understand and work with the output in such cases.

I have already implemented a working solution with test cases using an additional parameter, analogous to .null. I would like to contribute it to the tidyverse/glue package. Before creating a pull request, I wanted to open an issue to discuss the potential changes, gather feedback, and ensure that the new feature aligns with the project's goals and guidelines.

Please let me know your thoughts on this proposed feature, and if it's something you'd be interested in incorporating into the tidyverse/glue package.

Current implementation:
n1 <- "foo"
n2 <- character()
res <- glue::glue("{n1} and {n2} go together")
print(res)
#Output: character(0)
Suggested implementation:
n1 <- "foo"
n2 <- character()
res <- glue::glue("{n1} and {n2} go together", .empty = "bar")
print(res)
#Output: "foo and bar go together"
@jennybc
Copy link
Member

jennybc commented Sep 21, 2023

Yes, behaviour for length 0 input needs attention.

However, I'm closing this issue and the associated PR, because #246 already captures the need to better align glue with tidyverse recycling rules.

@jennybc jennybc closed this as completed Sep 21, 2023
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

No branches or pull requests

2 participants