R/centerText.R

Defines functions centerText

Documented in centerText

## Function to center text strings for display on the text console
## by prepending the necessary number of spaces to each element.
centerText <- function(x, width=getOption("width"))
  {
    retval <- vector(length=length(x), mode="character")
    for( i in 1:length(x) )
      {
        text <- trim(x[i])
        textWidth  <- nchar(text)
        nspaces <- floor((width - textWidth)/2)
        spaces <- paste( rep(" ",nspaces), sep="", collapse="")
        retval[i] <- paste( spaces, text, sep="", collapse="\n" )
      }
    retval
  }

Try the gdata package in your browser

Any scripts or data that you put into this service are public.

gdata documentation built on May 2, 2019, 5:49 p.m.