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"), add = FALSE )
x | a character vector, or a vector to be coerced to a character vector. |
---|---|
n | a positive integer indicating the size of character strings to be created or added. |
extra | 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. |
align | either "right", "left" or "center". If "right", then strings
will be right-aligned and so |
add | a logical should |
A character vector of the concatenated characters.
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.
#> [1] "myfilename001" "myfilename002" "myfilename010" "myfilename100"adjustStrings('# Comment ', 20, '#', align = "left")#> [1] "# Comment ##########"