tidyverse / stringr

A fresh approach to string manipulation in R
https://stringr.tidyverse.org
Other
603 stars 187 forks source link

Adds a message when an empty string is provided #568

Closed LouisMPenrod closed 1 month ago

LouisMPenrod commented 1 month ago

Returns a message instead of returning nothing which was the previous behavior. Existing snapshot updated.

Fixes #497

hadley commented 1 month ago

@DavisVaughan do you remember what we've done when we've printed length-0 objects in other packages?

DavisVaughan commented 1 month ago

You could use the vctrs approach and always unconditionally print a header

> vctrs::obj_print(1)
<double[1]>
[1] 1
> vctrs::obj_print(double())
<double[0]>

Like <stringr_view[0]> or something. So even in the empty case you get something.


But since this is mostly for interactive usage I don't mind something like No strings provided or something equally friendly. I don't really mind the current behavior much though, it is like glue::glue().

Do we also want to consider the str_view(character(), html = TRUE) case?

hadley commented 1 month ago

I consider html = TRUE basically superseded so no need to worry about it, I think.

hadley commented 1 month ago

Thanks for working on this and I hope you had fun at TDD 😁