stringr (version 0.6.1)

str_pad: Pad a string.

Description

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

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 (left, right or both)
pad
single padding character (default is a space)

Value

  • character vector

See Also

str_trim to remove whitespace

Examples

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

Run the code above in your browser using DataLab