shortenStrings: Shorten a string to a maximum length and indicate shorting by...

View source: R/fcn_misc.R

shortenStringsR Documentation

Shorten a string to a maximum length and indicate shorting by appending '..'

Description

Some axis labels are sometimes just too long and printing them will either squeeze the actual plot (ggplot) or make the labels disappear beyond the margins (graphics::plot) One ad-hoc way of avoiding this is to shorten the names, hoping they are still meaningful to the viewer.

Usage

shortenStrings(x, max_len = 20, verbose = TRUE, allow_duplicates = FALSE)

Arguments

x

Vector of input strings

max_len

Maximum length allowed

verbose

Print which strings were shortened

allow_duplicates

If shortened strings are not discernible any longer, consider the short version valid (not the default), otherwise (default) return the full string (–> no-op)

Details

This function should be applied AFTER you tried more gentle methods, such as delLCP or simplifyNames.

Value

A vector of shortened strings

See Also

delLCP, simplifyNames

Examples

r = shortenStrings(c("gamg_101", "gamg_101230100451", "jurkat_06_100731121305", "jurkat_06_1"))
all(r == c("gamg_101", "gamg_101230100..", "jurkat_06_1007..", "jurkat_06_1"))


cbielow/PTXQC documentation built on March 13, 2024, 5:08 a.m.