pad_c: Pad and join multiple strings within character vectors

Description Usage Arguments Value See Also Examples

Description

Joins one or more character vectors as in str_c but with the character strings in each vector padded to make them equal length. The last vector is by default left unpadded but can optionally be padded too.

Usage

1
pad_c(..., pad_last = FALSE, sep = " ", collapse = NULL)

Arguments

...

one or more character vectors as for str_c.

pad_last

logical: pad the last vector in addition to the others or leave it without padding?

sep

character: separator between vector elements.

collapse

character: optional string used to combine input vectors into a single string.

Value

character: a single string constructed in a similar way as with str_c but where vectors are padded to a uniform width. If collapse is NULL (the default) the returned value is a character vector with length equal to the length of the first input vector. If collapse is non-NULL, the returned value is a character vector of length 1.

See Also

str_c

Examples

1
2
3
4
5
6
7
8
9
vec1 <- c("Avocado:", "Blueberry:", "Coconut:", "Dill:")
vec2 <- c(rep("fruit", 3), "herb")
vec3 <- c("green", "purple", "white", "green")

pad_c(vec1, pad_last = TRUE)

cat(pad_c(vec1, vec2, collapse = "\n"), "\n")

cat(pad_c(vec1, vec2, vec3, collapse = "\n"), "\n")

toniprice/jutebag documentation built on May 12, 2019, 4:39 a.m.