Learn R Programming

formatters (version 0.5.0)

padstr: Pad a string and align within string

Description

Pad a string and align within string

Usage

padstr(x, n, just = c("center", "left", "right"))

Value

x, padded to be a string of n characters

Arguments

x

string

n

number of character of the output string, if n < nchar(x) an error is thrown

just

character(1). Text alignment justification to use. Defaults to center. Must be center, right or left.

Examples

Run this code

padstr("abc", 3)
padstr("abc", 4)
padstr("abc", 5)
padstr("abc", 5, "left")
padstr("abc", 5, "right")

if (interactive()) {
  padstr("abc", 1)
}

Run the code above in your browser using DataLab