stringr (version 0.5)

str_wrap: Wrap strings into nicely formatted paragraphs.

Description

Wrap strings into nicely formatted paragraphs.

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.
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 reformatted strings.

Details

This is currently implemented as thin wrapper over strwrap, but is vectorised over stringr, and collapses output into single strings. See strwrap for more details.

Examples

Run this code
thanks <- str_c(readLines(R.home("doc/THANKS")), 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")

Run the code above in your browser using DataLab