strsplit.wrap: Create substrings with a maximal length by splitting at...

View source: R/formatting.R

strsplit.wrapR Documentation

Create substrings with a maximal length by splitting at specific characters

Description

This function splits a string into substrings of length width or shorter. The splitting is done at the characters specified in split, in order of preference.

Usage

strsplit.wrap(x, width = 2000, split = c("\n", " ", ",", ""))

Arguments

x

A character vector of length 1.

width

The maximum character length to break the vector at.

split

A vector of regular expressions to match a character to break the string at. The function will try to break the string at the first value specified in this argument; if that fails, it will move on to the second, then the third, etc.

Details

This combines the functionality of base::strwrap() and base::strsplit(); instead of a string wrapped with newlines, the result is multiple substrings.

Value

A character vector consisting of strings of length width or shorter, and split at the characters specified in split.

Author(s)

Sercan Kahveci

Examples

thanks <- paste(readLines(file.path(R.home("doc"), "THANKS")), collapse = "\n")
strsplit.wrap(thanks,width=80)

alphabet <- paste0(letters,collapse="")
strsplit.wrap(alphabet,width=3)

Spiritspeak/skMisc documentation built on April 12, 2025, 5:40 a.m.