Learn R Programming

QCA (version 0.5-1)

prettyString: Separate a very long vector of strings on several rows

Description

When displaying the minimized prime implicants or the row names from the original dataset, it sometimes happens that this vector is too large to be displayed on a single row, therefore R splitts it at some letter when printing it. This function takes care of that, by specifying the maximum number of characters for each row such that no prime implicants or row names will be splitted.

Usage

prettyString(string.vector, string.width=60, repeat.space=5,
              separator=",")

Arguments

string.vector
a vector of strings
string.width
the length of the row, in number of characters (default to 60)
repeat.space
the number of space characters for the white space from the beginning of the line (default to 5)
separator
character to use for separating the vector elements (default to comma)

See Also

cat, strsplit, strwrap

Examples

Run this code
set.seed(1234)
long.string <- paste("This is a very long string, composed from the following words:", 
                 paste(sample(c("one","two","three"), 60, replace=TRUE), collapse=""))

long.string

string.vector <- unlist(strsplit(long.string, ""))

# a row length of 70, no space at the beginning
cat(prettyString(string.vector, 70, 0, ""), "")

# a row length of 50, inserting 7 spaces before each row
cat("", prettyString(string.vector, 50, 7, ""), "")

Run the code above in your browser using DataLab