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 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
Collaborator

I think this was done deliberately to mimic

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

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

@jimhester
Copy link
Collaborator

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

@jennybc
Copy link
Member Author

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants