str_wrap: Wrap strings into nicely formatted paragraphs.

Description Usage Arguments Value Examples

Description

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

Usage

1
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

1
2
3
4
5
6
7
8
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")

Example output

R would not be what it is today without the invaluable help of these people
outside of the R core team, who contributed by donating code, bug fixes and
documentation: Valerio Aimale, Thomas Baier, Henrik Bengtsson, Roger Bivand,
Ben Bolker, David Brahm, G"oran Brostr"om, Patrick Burns, Vince Carey, Saikat
DebRoy, Matt Dowle, Brian D'Urso, Lyndon Drake, Dirk Eddelbuettel, Claus
Ekstrom, Sebastian Fischmeister, John Fox, Paul Gilbert, Yu Gong, Gabor
Grothendieck, Frank E Harrell Jr, Torsten Hothorn, Robert King, Kjetil Kjernsmo,
Roger Koenker, Philippe Lambert, Jan de Leeuw, Jim Lindsey, Patrick Lindsey,
Catherine Loader, Gordon Maclean, John Maindonald, David Meyer, Ei-ji Nakama,
Jens Oehlschaegel, Steve Oncley, Richard O'Keefe, Hubert Palme, Roger D. Peng,
Jose' C. Pinheiro, Tony Plate, Anthony Rossini, Jonathan Rougier, Petr Savicky,
Guenther Sawitzki, Marc Schwartz, Arun Srinivasan, Detlef Steuer, Bill Simpson,
Gordon Smyth, Adrian Trapletti, Terry Therneau, Rolf Turner, Bill Venables,
Gregory R. Warnes, Andreas Weingessel, Morten Welinder, James Wettenhall, Simon
Wood, and Achim Zeileis. Others have written code that has been adopted by R and
is acknowledged in the code files, including 
R would not be what it is today
without the invaluable help of these
people outside of the R core team,
who contributed by donating code,
bug fixes and documentation: Valerio
Aimale, Thomas Baier, Henrik Bengtsson,
Roger Bivand, Ben Bolker, David Brahm,
G"oran Brostr"om, Patrick Burns, Vince
Carey, Saikat DebRoy, Matt Dowle,
Brian D'Urso, Lyndon Drake, Dirk
Eddelbuettel, Claus Ekstrom, Sebastian
Fischmeister, John Fox, Paul Gilbert,
Yu Gong, Gabor Grothendieck, Frank E
Harrell Jr, Torsten Hothorn, Robert
King, Kjetil Kjernsmo, Roger Koenker,
Philippe Lambert, Jan de Leeuw, Jim
Lindsey, Patrick Lindsey, Catherine
Loader, Gordon Maclean, John Maindonald,
David Meyer, Ei-ji Nakama, Jens
Oehlschaegel, Steve Oncley, Richard
O'Keefe, Hubert Palme, Roger D. Peng,
Jose' C. Pinheiro, Tony Plate, Anthony
Rossini, Jonathan Rougier, Petr Savicky,
Guenther Sawitzki, Marc Schwartz, Arun
Srinivasan, Detlef Steuer, Bill Simpson,
Gordon Smyth, Adrian Trapletti, Terry
Therneau, Rolf Turner, Bill Venables,
Gregory R. Warnes, Andreas Weingessel,
Morten Welinder, James Wettenhall, Simon
Wood, and Achim Zeileis. Others have
written code that has been adopted by R
and is acknowledged in the code files,
including 
  R would not be what it is today without the invaluable help
of these people outside of the R core team, who contributed
by donating code, bug fixes and documentation: Valerio
Aimale, Thomas Baier, Henrik Bengtsson, Roger Bivand,
Ben Bolker, David Brahm, G"oran Brostr"om, Patrick Burns,
Vince Carey, Saikat DebRoy, Matt Dowle, Brian D'Urso,
Lyndon Drake, Dirk Eddelbuettel, Claus Ekstrom, Sebastian
Fischmeister, John Fox, Paul Gilbert, Yu Gong, Gabor
Grothendieck, Frank E Harrell Jr, Torsten Hothorn, Robert
King, Kjetil Kjernsmo, Roger Koenker, Philippe Lambert, Jan
de Leeuw, Jim Lindsey, Patrick Lindsey, Catherine Loader,
Gordon Maclean, John Maindonald, David Meyer, Ei-ji Nakama,
Jens Oehlschaegel, Steve Oncley, Richard O'Keefe, Hubert
Palme, Roger D. Peng, Jose' C. Pinheiro, Tony Plate, Anthony
Rossini, Jonathan Rougier, Petr Savicky, Guenther Sawitzki,
Marc Schwartz, Arun Srinivasan, Detlef Steuer, Bill Simpson,
Gordon Smyth, Adrian Trapletti, Terry Therneau, Rolf Turner,
Bill Venables, Gregory R. Warnes, Andreas Weingessel, Morten
Welinder, James Wettenhall, Simon Wood, and Achim Zeileis.
Others have written code that has been adopted by R and is
acknowledged in the code files, including 
R would not be what it is today without the invaluable help
  of these people outside of the R core team, who contributed
  by donating code, bug fixes and documentation: Valerio
  Aimale, Thomas Baier, Henrik Bengtsson, Roger Bivand,
  Ben Bolker, David Brahm, G"oran Brostr"om, Patrick Burns,
  Vince Carey, Saikat DebRoy, Matt Dowle, Brian D'Urso,
  Lyndon Drake, Dirk Eddelbuettel, Claus Ekstrom, Sebastian
  Fischmeister, John Fox, Paul Gilbert, Yu Gong, Gabor
  Grothendieck, Frank E Harrell Jr, Torsten Hothorn, Robert
  King, Kjetil Kjernsmo, Roger Koenker, Philippe Lambert, Jan
  de Leeuw, Jim Lindsey, Patrick Lindsey, Catherine Loader,
  Gordon Maclean, John Maindonald, David Meyer, Ei-ji Nakama,
  Jens Oehlschaegel, Steve Oncley, Richard O'Keefe, Hubert
  Palme, Roger D. Peng, Jose' C. Pinheiro, Tony Plate, Anthony
  Rossini, Jonathan Rougier, Petr Savicky, Guenther Sawitzki,
  Marc Schwartz, Arun Srinivasan, Detlef Steuer, Bill Simpson,
  Gordon Smyth, Adrian Trapletti, Terry Therneau, Rolf Turner,
  Bill Venables, Gregory R. Warnes, Andreas Weingessel, Morten
  Welinder, James Wettenhall, Simon Wood, and Achim Zeileis.
  Others have written code that has been adopted by R and is
  acknowledged in the code files, including 
R
  would
  not
  be
  what
  it
  is
  today
  without
  the
  invaluable
  help
  of
  these
  people
  outside
  of
  the
  R
  core
  team,
  who
  contributed
  by
  donating
  code,
  bug
  fixes
  and
  documentation:
  Valerio
  Aimale,
  Thomas
  Baier,
  Henrik
  Bengtsson,
  Roger
  Bivand,
  Ben
  Bolker,
  David
  Brahm,
  G"oran
  Brostr"om,
  Patrick
  Burns,
  Vince
  Carey,
  Saikat
  DebRoy,
  Matt
  Dowle,
  Brian
  D'Urso,
  Lyndon
  Drake,
  Dirk
  Eddelbuettel,
  Claus
  Ekstrom,
  Sebastian
  Fischmeister,
  John
  Fox,
  Paul
  Gilbert,
  Yu
  Gong,
  Gabor
  Grothendieck,
  Frank
  E
  Harrell
  Jr,
  Torsten
  Hothorn,
  Robert
  King,
  Kjetil
  Kjernsmo,
  Roger
  Koenker,
  Philippe
  Lambert,
  Jan
  de
  Leeuw,
  Jim
  Lindsey,
  Patrick
  Lindsey,
  Catherine
  Loader,
  Gordon
  Maclean,
  John
  Maindonald,
  David
  Meyer,
  Ei-
  ji
  Nakama,
  Jens
  Oehlschaegel,
  Steve
  Oncley,
  Richard
  O'Keefe,
  Hubert
  Palme,
  Roger
  D.
  Peng,
  Jose'
  C.
  Pinheiro,
  Tony
  Plate,
  Anthony
  Rossini,
  Jonathan
  Rougier,
  Petr
  Savicky,
  Guenther
  Sawitzki,
  Marc
  Schwartz,
  Arun
  Srinivasan,
  Detlef
  Steuer,
  Bill
  Simpson,
  Gordon
  Smyth,
  Adrian
  Trapletti,
  Terry
  Therneau,
  Rolf
  Turner,
  Bill
  Venables,
  Gregory
  R.
  Warnes,
  Andreas
  Weingessel,
  Morten
  Welinder,
  James
  Wettenhall,
  Simon
  Wood,
  and
  Achim
  Zeileis.
  Others
  have
  written
  code
  that
  has
  been
  adopted
  by
  R
  and
  is
  acknowledged
  in
  the
  code
  files,
  including 

stringr documentation built on May 2, 2019, 11:03 a.m.