Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

centerText

Center Text Strings


Description

Function to center text strings for display on the text console by prepending the necessary number of spaces to each element.

Usage

centerText(x, width = getOption("width"))

Arguments

x

Character vector containing text strings to be centered.

width

Desired display width. Defaults to the R display width given by getOption("width").

Details

Each element will be centered individually by prepending the necessary number of spaces to center the text in the specified display width assuming a fixed width font.

Value

Vector of character strings.

Author(s)

Gregory R. Warnes greg@warnes.net

See Also

Examples

cat(centerText("One Line Test"), "\n\n")

mText <-c("This", "is an example",
          " of a multiline text    ",
          "with ",
          "          leading",
          " and trailing         ",
          "spaces.")
cat("\n", centerText(mText), "\n", sep="\n")

gdata

Various R Programming Tools for Data Manipulation

v2.18.0
GPL-2
Authors
Gregory R. Warnes, Ben Bolker, Gregor Gorjanc, Gabor Grothendieck, Ales Korosec, Thomas Lumley, Don MacQueen, Arni Magnusson, Jim Rogers, and others
Initial release
2017-06-05

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.