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

glue_collapse() should always return length 1 vectors #88

Closed
krlmlr opened this issue Apr 13, 2018 · 5 comments · Fixed by #295
Closed

glue_collapse() should always return length 1 vectors #88

krlmlr opened this issue Apr 13, 2018 · 5 comments · Fixed by #295
Labels
bug an unexpected problem or unintended behavior

Comments

@krlmlr
Copy link
Member

krlmlr commented Apr 13, 2018

length(glue::glue_collapse(character()))
#> [1] 0
length(glue::glue_collapse(""))
#> [1] 1
length(glue::glue_collapse(letters))
#> [1] 1

Created on 2018-04-13 by the reprex package (v0.2.0).

Perhaps glue_collapse() should always returned a string?

@jimhester
Copy link
Collaborator

Those are all characters, how is this not type stable?

@krlmlr
Copy link
Member Author

krlmlr commented Apr 13, 2018

The length varies (length 1 vs. length 0), I can't map_chr(..., glue_collapse). Maybe there's a better term for this feature?

@jimhester
Copy link
Collaborator

Ah I see, I think 0 length inputs generating 0 length outputs is the correct behavior, but can see how it makes this particular idiom more painful.

@krlmlr
Copy link
Member Author

krlmlr commented Apr 13, 2018

Maybe for vectorized operations, but not for summaries?

library(tidyverse)
tibble(a = numeric()) %>% summarize(sum(a))
#> # A tibble: 1 x 1
#>   `sum(a)`
#>      <dbl>
#> 1       0.

Created on 2018-04-13 by the reprex package (v0.2.0).

@jimhester jimhester added the feature a feature request or enhancement label Jul 16, 2018
@krlmlr
Copy link
Member Author

krlmlr commented Apr 12, 2020

Do we want a length-stable variant, perhaps glue_collapse1()?

https://github.com/krlmlr/dm/blob/23b37be9280a227bd21cad8d652a3f6a632ef76a/R/paste.R#L95-L101

@hadley hadley added bug an unexpected problem or unintended behavior and removed feature a feature request or enhancement labels Jan 25, 2023
@hadley hadley changed the title Type stability of glue_collapse() glue_collapse() should always return length 1 vetors Jan 25, 2023
@hadley hadley changed the title glue_collapse() should always return length 1 vetors glue_collapse() should always return length 1 vectors Jan 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants