Adjust the size of character strings by adding extra characters. It allows to constraint the size of the string or to add a specific number of extra characters.

adjustStrings(
x,
n,
extra = 0,
align = c("right", "left", "center"),
)

Arguments

x a character vector, or a vector to be coerced to a character vector. a positive integer indicating the size of character strings to be created or added. a character vector, or a vector to be coerced to a character vector that will be (partially) added to produced a string of a specific length. either "right", "left" or "center". If "right", then strings will be right-aligned and so extra's characters will be added to the left. "right" is the opposite of "left" and if align = "center", then extra characters will be split in half and added on both sides. a logical should extra be added, in which case n characters will be added to input strings.

Value

A character vector of the concatenated characters.

Details

This function was originally created to help getting a fixed number of digits when naming files. The current version is more general, it allows to add any string before or after to adjust the size. Not that if a character is longer than expected, it will be adequately cut off.

base::sprintf()
paste0('myfilename', adjustStrings(c(1:2,10,100), 3))
#> [1] "# Comment ##########"