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

Add whitespace_only option to str_wrap() #335

Closed
chris2b5 opened this issue Apr 10, 2020 · 3 comments
Closed

Add whitespace_only option to str_wrap() #335

chris2b5 opened this issue Apr 10, 2020 · 3 comments
Labels
feature a feature request or enhancement

Comments

@chris2b5
Copy link

Description

str_wrap sometimes inserts newlines at unwanted positions. The underlying function stringi::stri_wrap provides an option whitespace_only to force it to wrap only at whitespace. Exposing this option in the interface to str_wrap would provide an easy way to avoid this in many cases.

Reprex

library(stringr)
cat(str_wrap("weighted time spent doing I/Os (ms)", width = 14))
#> weighted time
#> spent doing I/
#> Os (ms)

# expected output:
cat(stringi::stri_wrap("weighted time spent doing I/Os (ms)", width = 14,
                       simplify = FALSE, whitespace_only = TRUE) %>%
      vapply(., str_c, collapse = "\n", character(1))
)
#> weighted time
#> spent doing
#> I/Os (ms)

Created on 2020-04-10 by the reprex package (v0.3.0)

@hadley hadley added the feature a feature request or enhancement label Apr 20, 2020
@hadley
Copy link
Member

hadley commented Apr 20, 2020

Could this just be the default?

@chris2b5
Copy link
Author

Could this just be the default?

Actually, yes - would be fine by me!

@francisbarton
Copy link

The whitespace_only parameter is just what I was looking for with a recent project - thanks!
The option is documented on the official stringr reference site - which made me think I could use it already. But I am just on the CRAN version of stringr (1.4.0), so it's not yet available.
Aside: I think features that are only available in the development version should be flagged as such in the docs. (Or: how do you switch between the docs for the latest release and the docs for the dev version on the tidyverse site?)

I think I will wait for this option to reach CRAN, rather than switching to the dev version. I've used chris's stringi solution for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants