Learn R Programming

wrMisc (version 2.1.1)

truncateVect: Truncating Text Vector To Specific Length

Description

This function allows truncating a text vector (or matrix of text) at nMax number of characters with optional adding of truncation/ending sign and trimming after last separator.

Usage

truncateVect(
  x,
  nMax = 20,
  sep = NULL,
  appendChar = "...",
  startFrom = 1,
  silent = FALSE,
  debug = FALSE,
  callFrom = NULL
)

Value

This function returns a data.frame or matrix (if no annotation added) with values (and annotation) conform to fiter criteria

Arguments

x

(character or matrix of text) main input, text to be truncated

nMax

(integer, length=1) max length in number of characters to be returned

sep

(character or NULL) optional separator to be considered : Truncation will happen before the separator; set to NULL for ignoring

appendChar

(character, length=1) optional set of characters to add at end when trucation has happened (default '...'); set to NULL or "" for not appending anything

startFrom

(integer, length=1) designes the first character to be extracted (see also substr )

silent

(logical) suppress messages

debug

(logical) display additional messages for debugging

callFrom

(character) allow easier tracking of messages produced

Details

convenient access to results produced using the functions substr or moderTest2grp. The user can define the threshold and which type of multiple testing correction should be used (as long as the multiple testing correction method cited was actually performed as part of testing).

This function builds on substr but offers additional options for trimming at right side of text: In contrast to substr where the absolute position number has to be given, this function takes the max desired length of the resulting character vector (argument nMax). The argument appendChar allows adding extra characters (default '...') indicating that trimmming has been performed. When doing so, the text will be trimmed further inside to ensure the final length of the resulting text, as defined by argument nMax.

Furthermore, using the argument sep it is possible to respect entities between separators and only cut at/before such separators (the resulting text vecor may thus be shorter than specified globally with argument nMax).

See Also

Examples

Run this code
txt <- c("abc", "abcdefgh", "abc/def/gh")
truncateVect(txt, nMax=7, appendChar="..")
truncateVect(txt, nMax=7, sep="/", appendChar="..")

Run the code above in your browser using DataLab