pad_c: Pad and join multiple strings within character vectors

View source: R/pad_c.R

pad_cR Documentation

Pad and join multiple strings within character vectors

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

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

Arguments

...

One or more character vectors as for str_c.

pad_last

A logical specifying whether to pad the last vector in addition to the others or leave it without padding.

sep

The string separator between vector elements.

collapse

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

Value

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

vec1 <- c("Avocado:", "Blueberry:", "Coconut:", "Dill:")
vec2 <- c(rep("fruit", 3), "herb")
vec3 <- c("green", "purple", "brown", "green")

pad_c(vec1, pad_last = TRUE)

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

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

pad_c(vec1, vec3, sep = " ... ", collapse = "; ")


toniprice/jute documentation built on Jan. 11, 2023, 8:23 a.m.