adjustStrings: Adjust the size of character strings

View source: R/adjustStrings.R

adjustStringsR Documentation

Adjust the size of character strings

Description

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.

Usage

adjustStrings(
  x,
  n,
  extra = 0,
  align = c("right", "left", "center"),
  add = FALSE
)

Arguments

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 extra's characters will be added to the left. "right" is the opposite of "left" and if align = "center", then extra characters will be split in half and added on both sides.

add

a logical should extra be added, in which case n characters will be added to input strings.

Details

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.

Value

A character vector of the concatenated characters.

See Also

base::sprintf()

Examples

paste0('myfilename', adjustStrings(c(1:2,10,100), 3))
adjustStrings('# Comment ', 20, '#', align = "left")

inSileco/letiRmisc documentation built on Sept. 16, 2022, 2:19 p.m.