trim_each_part: Abbreviate elements

View source: R/utils.R

trim_each_partR Documentation

Abbreviate elements

Description

Split string elements in character vector or words in a string and abbreviate to specified number of characters.

Usage

trim_each_part(v, split = ",", trim_x = 3, paste_back = T)

Arguments

v

A character vector.

split

Character delimiter to split by. Note: escape characters still apply, e.g. for ".", split = "\."

trim_x

Number, indicating the number of characters for each part (that is, length of truncated output string).

paste_back

Logical - paste the split elements back together?

Value

The abbreviated charactere elements

Examples

trim_each_part("abbreviate this", sep = " ")
z <- paste(rep("high", 4), rep(c("low", "intermediate"), each = 2), sep = "/")
# [1] "high/low"          "high/low"          "high/intermediate" "high/intermediate"
trim_each_part(paste(x, y, sep = "/"), split = "/")
# [1] "hig/low" "hig/low" "hig/int" "hig/int"
trim_each_part(z, split = "/", trim_x = 2)
# [1] "hi/lo" "hi/lo" "hi/in" "hi/in"
trim_each_part(z, split = "/", paste_back = F)
# [1] "hig" "low" "hig" "low" "hig" "int" "hig" "int"

kazeera/hourglass documentation built on April 5, 2025, 7:18 a.m.