strwrapx: Wrap strings at white space and + symbols

Description Usage Arguments Details Examples

View source: R/mle.R

Description

Extended (hacked) version of strwrap: wraps a string at whitespace and plus symbols

Usage

1
2
3
strwrapx(x, width = 0.9 * getOption("width"), indent = 0,
exdent = 0, prefix = "", simplify = TRUE,
parsplit = "\n[ \t\n]*\n", wordsplit = "[ \t\n]")

Arguments

x

a character vector, or an object which can be converted to a character vector by as.character.

width

a positive integer giving the target column for wrapping lines in the output.

indent

a non-negative integer giving the indentation of the first line in a paragraph.

exdent

a non-negative integer specifying the indentation of subsequent lines in paragraphs.

prefix

a character string to be used as prefix for each line.

simplify

a logical. If TRUE, the result is a single character vector of line text; otherwise, it is a list of the same length as x the elements of which are character vectors of line text obtained from the corresponding element of x. (Hence, the result in the former case is obtained by unlisting that of the latter.)

parsplit

Regular expression describing how to split paragraphs

wordsplit

Regular expression decribing how to split words

Details

Whitespace in the input is destroyed. Double spaces after periods (thought as representing sentence ends) are preserved. Currently, possible sentence ends at line breaks are not considered specially.

Indentation is relative to the number of characters in the prefix string.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
## Read in file 'THANKS'.
x <- paste(readLines(file.path(R.home("doc"), "THANKS")), collapse = "\n")
## Split into paragraphs and remove the first three ones
x <- unlist(strsplit(x, "\n[ \t\n]*\n"))[-(1:3)]
## Join the rest
x <- paste(x, collapse = "\n\n")
## Now for some fun:
writeLines(strwrap(x, width = 60))
writeLines(strwrap(x, width = 60, indent = 5))
writeLines(strwrap(x, width = 60, exdent = 5))
writeLines(strwrap(x, prefix = "THANKS> "))

## Note that messages are wrapped AT the target column indicated by
## 'width' (and not beyond it).
## From an R-devel posting by J. Hosking <jh910@juno.com>.
x <- paste(sapply(sample(10, 100, rep=TRUE),
           function(x) substring("aaaaaaaaaa", 1, x)), collapse = " ")
sapply(10:40,
       function(m)
       c(target = m, actual = max(nchar(strwrap(x, m)))))

Example output

Loading required package: stats4
J. D. Beasley, David J. Best, Richard Brent, Kevin Buhr,
Michael A. Covington, Bill Cleveland, Robert Cleveland,, G.
W. Cran, C. G. Ding, Ulrich Drepper, Paul Eggert, J. O.
Evans, David M. Gay, H. Frick, G. W. Hill, Richard H.
Jones, Eric Grosse, Shelby Haberman, Bruno Haible, John
Hartigan, Andrew Harvey, Trevor Hastie, Min Long Lam,
George Marsaglia, K. J. Martin, Gordon Matzigkeit, C. R.
Mckenzie, Jean McRae, Cyrus Mehta, Fionn Murtagh, John C.
Nash, Finbarr O'Sullivan, R. E. Odeh, William Patefield,
Nitin Patel, Alan Richardson, D. E. Roberts, Patrick
Royston, Russell Lenth, Ming-Jen Shyu, Richard C.
Singleton, S. G. Springer, Supoj Sutanthavibul, Irma
Terpenning, G. E. Thomas, Rob Tibshirani, Wai Wan Tsang,
Berwin Turlach, Gary V. Vaughan, Michael Wichura, Jingbo
Wang, M. A. Wong, and the Free Software Foundation (for
autoconf code and utilities). See also files under
src/extras.

Many more, too numerous to mention here, have contributed
by sending bug reports and suggesting various improvements.

Simon Davies whilst at the University of Auckland wrote the
original version of glm().

Julian Harris and Wing Kwong (Tiki) Wan whilst at the
University of Auckland assisted Ross Ihaka with the
original Macintosh port.

R was inspired by the S environment which has been
principally developed by John Chambers, with substantial
input from Douglas Bates, Rick Becker, Bill Cleveland,
Trevor Hastie, Daryl Pregibon and Allan Wilks.

A special debt is owed to John Chambers who has graciously
contributed advice and encouragement in the early days of R
and later became a member of the core team.

Stefano Iacus (a former member of R Core) and Simon Urbanek
developed the macOS port, including the R.app GUI,
toolchains and packaging.

The Windows port was developed by Guido Masarotto (for a
while a member of R Core) and Brian Ripley, then Duncan
Murdoch (a former member of R Core) and currently by Jeroen
Ooms (base) and Uwe Ligges (packages).

Tomas Kalibera's work has been sponsored by Jan Vitek and
funded by his European Research Council grant "Evolving
Language Ecosystems (ELE)".

Computing support (including hardware, hosting and
infrastructure) has been provided/funded by the R
Foundation, employers of R-Core members (notably WU Wien,
ETH Zurich, U Oxford and U Iowa) and by Northeastern
University and the University of Kent.

Distributions of R contain the recommended packages, whose
authors/contributors are listed in their DESCRIPTION files.
     J. D. Beasley, David J. Best, Richard Brent, Kevin
Buhr, Michael A. Covington, Bill Cleveland, Robert
Cleveland,, G. W. Cran, C. G. Ding, Ulrich Drepper, Paul
Eggert, J. O. Evans, David M. Gay, H. Frick, G. W. Hill,
Richard H. Jones, Eric Grosse, Shelby Haberman, Bruno
Haible, John Hartigan, Andrew Harvey, Trevor Hastie, Min
Long Lam, George Marsaglia, K. J. Martin, Gordon
Matzigkeit, C. R. Mckenzie, Jean McRae, Cyrus Mehta, Fionn
Murtagh, John C. Nash, Finbarr O'Sullivan, R. E. Odeh,
William Patefield, Nitin Patel, Alan Richardson, D. E.
Roberts, Patrick Royston, Russell Lenth, Ming-Jen Shyu,
Richard C. Singleton, S. G. Springer, Supoj Sutanthavibul,
Irma Terpenning, G. E. Thomas, Rob Tibshirani, Wai Wan
Tsang, Berwin Turlach, Gary V. Vaughan, Michael Wichura,
Jingbo Wang, M. A. Wong, and the Free Software Foundation
(for autoconf code and utilities). See also files under
src/extras.

     Many more, too numerous to mention here, have
contributed by sending bug reports and suggesting various
improvements.

     Simon Davies whilst at the University of Auckland
wrote the original version of glm().

     Julian Harris and Wing Kwong (Tiki) Wan whilst at the
University of Auckland assisted Ross Ihaka with the
original Macintosh port.

     R was inspired by the S environment which has been
principally developed by John Chambers, with substantial
input from Douglas Bates, Rick Becker, Bill Cleveland,
Trevor Hastie, Daryl Pregibon and Allan Wilks.

     A special debt is owed to John Chambers who has
graciously contributed advice and encouragement in the
early days of R and later became a member of the core team.

     Stefano Iacus (a former member of R Core) and Simon
Urbanek developed the macOS port, including the R.app GUI,
toolchains and packaging.

     The Windows port was developed by Guido Masarotto (for
a while a member of R Core) and Brian Ripley, then Duncan
Murdoch (a former member of R Core) and currently by Jeroen
Ooms (base) and Uwe Ligges (packages).

     Tomas Kalibera's work has been sponsored by Jan Vitek
and funded by his European Research Council grant "Evolving
Language Ecosystems (ELE)".

     Computing support (including hardware, hosting and
infrastructure) has been provided/funded by the R
Foundation, employers of R-Core members (notably WU Wien,
ETH Zurich, U Oxford and U Iowa) and by Northeastern
University and the University of Kent.

     Distributions of R contain the recommended packages,
whose authors/contributors are listed in their DESCRIPTION
files.
J. D. Beasley, David J. Best, Richard Brent, Kevin Buhr,
     Michael A. Covington, Bill Cleveland, Robert
     Cleveland,, G. W. Cran, C. G. Ding, Ulrich Drepper,
     Paul Eggert, J. O. Evans, David M. Gay, H. Frick, G.
     W. Hill, Richard H. Jones, Eric Grosse, Shelby
     Haberman, Bruno Haible, John Hartigan, Andrew Harvey,
     Trevor Hastie, Min Long Lam, George Marsaglia, K. J.
     Martin, Gordon Matzigkeit, C. R. Mckenzie, Jean McRae,
     Cyrus Mehta, Fionn Murtagh, John C. Nash, Finbarr
     O'Sullivan, R. E. Odeh, William Patefield, Nitin
     Patel, Alan Richardson, D. E. Roberts, Patrick
     Royston, Russell Lenth, Ming-Jen Shyu, Richard C.
     Singleton, S. G. Springer, Supoj Sutanthavibul, Irma
     Terpenning, G. E. Thomas, Rob Tibshirani, Wai Wan
     Tsang, Berwin Turlach, Gary V. Vaughan, Michael
     Wichura, Jingbo Wang, M. A. Wong, and the Free
     Software Foundation (for autoconf code and utilities).
     See also files under src/extras.

Many more, too numerous to mention here, have contributed
     by sending bug reports and suggesting various
     improvements.

Simon Davies whilst at the University of Auckland wrote the
     original version of glm().

Julian Harris and Wing Kwong (Tiki) Wan whilst at the
     University of Auckland assisted Ross Ihaka with the
     original Macintosh port.

R was inspired by the S environment which has been
     principally developed by John Chambers, with
     substantial input from Douglas Bates, Rick Becker,
     Bill Cleveland, Trevor Hastie, Daryl Pregibon and
     Allan Wilks.

A special debt is owed to John Chambers who has graciously
     contributed advice and encouragement in the early days
     of R and later became a member of the core team.

Stefano Iacus (a former member of R Core) and Simon Urbanek
     developed the macOS port, including the R.app GUI,
     toolchains and packaging.

The Windows port was developed by Guido Masarotto (for a
     while a member of R Core) and Brian Ripley, then
     Duncan Murdoch (a former member of R Core) and
     currently by Jeroen Ooms (base) and Uwe Ligges
     (packages).

Tomas Kalibera's work has been sponsored by Jan Vitek and
     funded by his European Research Council grant
     "Evolving Language Ecosystems (ELE)".

Computing support (including hardware, hosting and
     infrastructure) has been provided/funded by the R
     Foundation, employers of R-Core members (notably WU
     Wien, ETH Zurich, U Oxford and U Iowa) and by
     Northeastern University and the University of Kent.

Distributions of R contain the recommended packages, whose
     authors/contributors are listed in their DESCRIPTION
     files.
THANKS> J. D. Beasley, David J. Best, Richard Brent, Kevin Buhr,
THANKS> Michael A. Covington, Bill Cleveland, Robert Cleveland,, G. W.
THANKS> Cran, C. G. Ding, Ulrich Drepper, Paul Eggert, J. O. Evans,
THANKS> David M. Gay, H. Frick, G. W. Hill, Richard H. Jones, Eric
THANKS> Grosse, Shelby Haberman, Bruno Haible, John Hartigan, Andrew
THANKS> Harvey, Trevor Hastie, Min Long Lam, George Marsaglia, K. J.
THANKS> Martin, Gordon Matzigkeit, C. R. Mckenzie, Jean McRae, Cyrus
THANKS> Mehta, Fionn Murtagh, John C. Nash, Finbarr O'Sullivan, R. E.
THANKS> Odeh, William Patefield, Nitin Patel, Alan Richardson, D. E.
THANKS> Roberts, Patrick Royston, Russell Lenth, Ming-Jen Shyu, Richard
THANKS> C. Singleton, S. G. Springer, Supoj Sutanthavibul, Irma
THANKS> Terpenning, G. E. Thomas, Rob Tibshirani, Wai Wan Tsang, Berwin
THANKS> Turlach, Gary V. Vaughan, Michael Wichura, Jingbo Wang, M. A.
THANKS> Wong, and the Free Software Foundation (for autoconf code and
THANKS> utilities). See also files under src/extras.
THANKS> 
THANKS> Many more, too numerous to mention here, have contributed by
THANKS> sending bug reports and suggesting various improvements.
THANKS> 
THANKS> Simon Davies whilst at the University of Auckland wrote the
THANKS> original version of glm().
THANKS> 
THANKS> Julian Harris and Wing Kwong (Tiki) Wan whilst at the
THANKS> University of Auckland assisted Ross Ihaka with the original
THANKS> Macintosh port.
THANKS> 
THANKS> R was inspired by the S environment which has been principally
THANKS> developed by John Chambers, with substantial input from Douglas
THANKS> Bates, Rick Becker, Bill Cleveland, Trevor Hastie, Daryl
THANKS> Pregibon and Allan Wilks.
THANKS> 
THANKS> A special debt is owed to John Chambers who has graciously
THANKS> contributed advice and encouragement in the early days of R and
THANKS> later became a member of the core team.
THANKS> 
THANKS> Stefano Iacus (a former member of R Core) and Simon Urbanek
THANKS> developed the macOS port, including the R.app GUI, toolchains
THANKS> and packaging.
THANKS> 
THANKS> The Windows port was developed by Guido Masarotto (for a while
THANKS> a member of R Core) and Brian Ripley, then Duncan Murdoch (a
THANKS> former member of R Core) and currently by Jeroen Ooms (base)
THANKS> and Uwe Ligges (packages).
THANKS> 
THANKS> Tomas Kalibera's work has been sponsored by Jan Vitek and
THANKS> funded by his European Research Council grant "Evolving
THANKS> Language Ecosystems (ELE)".
THANKS> 
THANKS> Computing support (including hardware, hosting and
THANKS> infrastructure) has been provided/funded by the R Foundation,
THANKS> employers of R-Core members (notably WU Wien, ETH Zurich, U
THANKS> Oxford and U Iowa) and by Northeastern University and the
THANKS> University of Kent.
THANKS> 
THANKS> Distributions of R contain the recommended packages, whose
THANKS> authors/contributors are listed in their DESCRIPTION files.
       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
target   10   11   12   13   14   15   16   17   18    19    20    21    22
actual   10   10   11   12   13   14   15   16   17    18    19    20    21
       [,14] [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] [,24] [,25]
target    23    24    25    26    27    28    29    30    31    32    33    34
actual    22    23    24    25    26    27    28    29    30    31    32    33
       [,26] [,27] [,28] [,29] [,30] [,31]
target    35    36    37    38    39    40
actual    34    35    36    37    38    39

bbmle documentation built on May 2, 2019, 4:54 p.m.