strPart: Extract a defined part of a text string with separated...

View source: R/strPart.R

strPartR Documentation

Extract a defined part of a text string with separated elements

Description

Wrapper for strsplit. One defines the element of the string to return after splitting, with option to convert back to a character vector or leave as list. See strsplit for further description of most arguments.

Usage

strPart(x, part = 1, split = NULL, fixed = TRUE, returnVector = TRUE, ...)

Arguments

x

character vector, each element of which is to be split. Other inputs, including a factor, will give an error.

part

numeric. Part of string (between splits) to return.

split

character. The splitting character. See strsplit

fixed

logical. Default TRUE. See strsplit

returnVector

logical. Function relies on lapply, and thus returns a list. Set to 'TRUE' (Default) to return a vector.

...

Further arguments passed to strsplit.

Value

vector or list of character strings

Examples


# make example text string
txtStr <- paste(LETTERS[1:10], 13:22, letters[11:20], sep = "_")
txtStr

strPart(x = txtStr, part = 1, split = "_")
strPart(x = txtStr, part = 2, split = "_")
strPart(x = txtStr, part = 3, split = "_")

strPart(x = txtStr, part = 3, split = "_", returnVector = FALSE)


marchtaylor/sinkr documentation built on June 15, 2025, 1:17 a.m.