Skip to contents

Pad a string and align within string

Usage

padstr(x, n, just = list_valid_aligns())

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, left, dec_right, dec_left or decimal.

Value

x, padded to be a string of n characters

Examples


padstr("abc", 3)
#> [1] "abc"
padstr("abc", 4)
#> [1] "abc "
padstr("abc", 5)
#> [1] "abc  "
padstr("abc", 5, "left")
#> [1] "abc  "
padstr("abc", 5, "right")
#> [1] "  abc"

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