.devel/sphinx/rapi/strwrap.md

strwrap: Word-Wrap Text

Description

Splits each string into words which are then arranged to form text lines of mo more than a given width.

Usage

strwrap(
  x,
  width = 0.9 * getOption("width"),
  indent = 0,
  exdent = 0,
  prefix = "",
  simplify = TRUE,
  initial = prefix,
  locale = NULL
)

Arguments

| | | |----|----| | x | character vector whose elements are to be word-wrapped | | width | single integer; maximal total width of the code points per line (as determined by stri_width) | | indent | single integer; first line indentation size | | exdent | single integer; consequent lines indentation size | | prefix | single string; prefix for each line except the first | | simplify | see Value | | initial | single string; prefix for the first line | | locale | NULL or "" for the default locale (see stri_locale_get) or a single string with a locale identifier, see stri_locale_list |

Details

Might be useful when displaying strings using a monospaced font.

Value

If simplify is FALSE, a list of length(x) numeric vectors is returned.

Otherwise, the function yields a character vector (in UTF-8). Note that the length of the output may be different than that of the input.

Due to this, no attributes are preserved.

Differences from Base R

Replacement for base strwrap implemented with stri_wrap.

Author(s)

Marek Gagolewski

References

D.E. Knuth, M.F. Plass, Breaking paragraphs into lines, Software: Practice and Experience 11(11), 1981, pp. 1119--1184.

See Also

The official online manual of stringx at https://stringx.gagolewski.com/

Related function(s): sprintf, trimws, nchar

Examples

strwrap(paste0(
    strrep("az ", 20),
    strrep("\u0105\u20AC ", 20),
    strrep("\U0001F643 ", 20),
    strrep("\U0001F926\U0000200D\U00002642\U0000FE0F ", 20)
), width=60)
## [1] "az az az az az az az az az az az az az az az az az az az az"                    
## [2] "ą€ ą€ ą€ ą€ ą€ ą€ ą€ ą€ ą€ ą€ ą€ ą€ ą€ ą€ ą€ ą€ ą€ ą€ ą€ ą€"                    
## [3] "🙃 🙃 🙃 🙃 🙃 🙃 🙃 🙃 🙃 🙃 🙃 🙃 🙃 🙃 🙃 🙃 🙃 🙃 🙃 🙃"                    
## [4] "🤦‍♂️ 🤦‍♂️ 🤦‍♂️ 🤦‍♂️ 🤦‍♂️ 🤦‍♂️ 🤦‍♂️ 🤦‍♂️ 🤦‍♂️ 🤦‍♂️ 🤦‍♂️ 🤦‍♂️ 🤦‍♂️ 🤦‍♂️ 🤦‍♂️ 🤦‍♂️ 🤦‍♂️ 🤦‍♂️ 🤦‍♂️ 🤦‍♂️"


gagolews/stringx documentation built on Jan. 15, 2025, 9:46 p.m.