strtrimcommon: Trim common portions from both sides of a vector of strings

View source: R/strtrimcommon.R

strtrimcommonR Documentation

Trim common portions from both sides of a vector of strings

Description

Trim common portions from both sides of a vector of strings

Usage

strtrimcommon(x, split = "", USE.NAMES = FALSE, return.all = FALSE)

Arguments

x

A vector of strings

split

A character to use for splitting. If split is empty (i.e. split = ''), x is split into single characters. Otherwise, x is split on split boundaries.

USE.NAMES

logical; if TRUE use x as names for the result.

return.all

logical; if FALSE (the default), returns only the striped strings. If TRUE, returns a list with elements left, strings, right, containing left and right common portions, and the trimmed strings, respectively.

Value

A (named) vector of strings, or a list of string vectors (see parameter return.all for details).

Author(s)

Michaja Pehl

Examples

x <- c('/tmp/remind2_test-convGDX2MIF_fulldata.gdx',
       '/tmp/remind2_test-Ariadne_fulldata.gdx',
       '/tmp/remind2_test-NAVIGATE_fulldata.gdx',
       '/tmp/remind2_test-NGFS_fulldata_oneRegi.gdx',
       '/tmp/remind2_test-SHAPE_fulldata.gdx')

strtrimcommon(x, USE.NAMES = TRUE)

x <- c('Some|name|with|common|text|elements',
       'Some|name|without|extra|text|elements')

strtrimcommon(x, split = '|', return.all = TRUE)

pik-piam/quitte documentation built on April 26, 2024, 12:58 a.m.