Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

str_wrap

Wrap strings into nicely formatted paragraphs.


Description

This is a wrapper around stringi::stri_wrap() which implements the Knuth-Plass paragraph wrapping algorithm.

Usage

str_wrap(string, width = 80, indent = 0, exdent = 0)

Arguments

string

character vector of strings to reformat.

width

positive integer giving target line width in characters. A width less than or equal to 1 will put each word on its own line.

indent

non-negative integer giving indentation of first line in each paragraph

exdent

non-negative integer giving indentation of following lines in each paragraph

Value

A character vector of re-wrapped strings.

Examples

thanks_path <- file.path(R.home("doc"), "THANKS")
thanks <- str_c(readLines(thanks_path), collapse = "\n")
thanks <- word(thanks, 1, 3, fixed("\n\n"))
cat(str_wrap(thanks), "\n")
cat(str_wrap(thanks, width = 40), "\n")
cat(str_wrap(thanks, width = 60, indent = 2), "\n")
cat(str_wrap(thanks, width = 60, exdent = 2), "\n")
cat(str_wrap(thanks, width = 0, exdent = 2), "\n")

stringr

Simple, Consistent Wrappers for Common String Operations

v1.4.0
GPL-2 | file LICENSE
Authors
Hadley Wickham [aut, cre, cph], RStudio [cph, fnd]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.