Skip to content

Add whitespace_only option to str_wrap() #335

Description

@chris2b5

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancement

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions