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

collapse() when x has length zero #28

jennybc opened this Issue May 20, 2017 · 3 comments


None yet
2 participants

jennybc commented May 20, 2017

It feels like collapse() would be more consistent with glue() (and more convenient) if it returned character(0) if the input has length zero.

glue("{x}", x = "hi")
#> hi
glue("{x}", x = character(0))
#> character(0)
collapse(x = c("hi", "bye"), last = " and ")
#> [1] "hi and bye"
collapse(x = c(NULL, "bye"), last = " and ")
#> [1] "bye"
collapse(x = c("hi", NULL), last = " and ")
#> [1] "hi"
collapse(x = NULL, last = " and ")
#> [1] ""
collapse(x = character(), last = " and ")
#> [1] ""

This comment has been minimized.


jimhester commented May 22, 2017

I think this was done deliberately to mimic

paste(collapse = "", character())
#> ""

But I could be easily swayed to return character() here...


This comment has been minimized.


jimhester commented May 22, 2017

It is probably a good philosophy to always return 0 length outputs for 0 length inputs, so I will change this.

@jimhester jimhester closed this in b87fdb6 May 22, 2017


This comment has been minimized.


jennybc commented May 22, 2017

Yeah I was looking to glue to save me from the behaviour of paste(collapse = "", character()). Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment