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

collapse() when x has length zero #28

Closed
jennybc opened this issue May 20, 2017 · 3 comments
Closed

collapse() when x has length zero #28

jennybc opened this issue May 20, 2017 · 3 comments

Comments

@jennybc
Copy link
Member

@jennybc 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.

library(glue)
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] ""
@jimhester
Copy link
Member

@jimhester 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...

@jimhester
Copy link
Member

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

@jennybc 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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants