stringr (version 0.3)

str_pad: Pad a string.

Description

Pad a string.

Usage

str_pad(string, width, side="left", pad=" ")

Arguments

string
input character vector
width
pad strings to this minimum width
side
side on which padding character is added
pad
single padding character (default is a space)

Value

  • character vector

Details

Vectorised over string. All other inputs should be of length 1.

Examples

Run this code
rbind(
str_pad("hadley", 30, "left"),
str_pad("hadley", 30, "right"),
str_pad("hadley", 30, "center")
)
# Longer strings are returned unchanged
str_pad("hadley", 3)

Run the code above in your browser using DataLab