#Create vector of strings
vec <- c("1", "to", "four", "_eight_")
#View vector
vec |> stringr::str_view()[1] │ 1
[2] │ to
[3] │ four
[4] │ _eight_
The function stringr::str_pads() adds white space to strings to ensure it is a minimum length.
Prior to using the function create a vector with strings of length 1, 2, 4, and 8.
Padding will add space to each string shorter than the specified pad length. These strings will have a total length (i.e. number of characters) equal to the pad length.
By default spaces () will be added to the start/left-side of the string for padding.
[1] │ 1
[2] │ to
[3] │ four
[4] │ _eight_
Strings with a length equal to or greater than the pad length will be untouched.
The side to add the padding characters can be specified.
[1] │ 1
[2] │ to
[3] │ four
[4] │ _eight_
[1] │ 1
[2] │ to
[3] │ four
[4] │ _eight_
The padding character can be specified. This character can only have a length of one (i.e. “ or”||” cannot be used).
[1] │ |||||||||1
[2] │ ||||||||to
[3] │ ||||||four
[4] │ |||_eight_
[1] │ .........1
[2] │ ........to
[3] │ ......four
[4] │ ..._eight_