glue
glue copied to clipboard
Type stability of glue_collapse()
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?
Those are all characters, how is this not type stable?
The length varies (length 1 vs. length 0), I can't map_chr(..., glue_collapse). Maybe there's a better term for this feature?
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.
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).
Do we want a length-stable variant, perhaps glue_collapse1()?
https://github.com/krlmlr/dm/blob/23b37be9280a227bd21cad8d652a3f6a632ef76a/R/paste.R#L95-L101