Skip to contents

Add characters to the ends of strings

Usage

str_indent(strings, times = 1, side = c("left", "right", "both"), indent = " ")

Arguments

strings

A character vector, where each element of the vector is a character string.

times

The number of times the indent should be repeated, on each side specified.

side

Which side of the string should the indent be applied, one of "left", "right" or "both". The left side is the default.

indent

The characters to be used to indent.

Value

A character vector of the same length as strings, with each element indented as specified by the times, indent, and side arguments.

See also

str_concat() and str_glue() for combining strings together.

Base paste0() and strrep() used by this function.

Examples

str_indent(c("Hello", "World"), 3)
#> [1] "   Hello" "   World"
str_indent(c("Hello", "World"), 3, indent = ".")
#> [1] "...Hello" "...World"
str_indent(c("Hello", "World"), 3, "both", "-")
#> [1] "---Hello---" "---World---"

# Get extra with it
"wow" |>
  str_indent(side = "both") |>
  str_indent(3, indent = "->>") |>
  str_indent(3,  side = "right", indent = "<<-") |>
  str_indent(2, side = "both", indent = "-||-") |>
  str_indent(2, indent = "[") |>
  str_indent(2, side = "right", indent = "]")
#> [1] "[[-||--||-->>->>->> wow <<-<<-<<--||--||-]]"