ftsplit: Fixed-token-split a scalar string into parts

View source: R/sbtab_utilities.R

ftsplitR Documentation

Fixed-token-split a scalar string into parts

Description

This function splits a string like strsplit, but it removes whitespace from the result (on both ends) and the split token is taken literally

Usage

ftsplit(str, s = " ", re = FALSE)

Arguments

str

a string (character vector of length 1)

s

a split token

re

defaults to FALSE, if TRUE s is treated as a regular expression

Value

a character vector of the components without leading or trailing whitespace

Examples

ftsplit(" A + 2*B ","+")
[1] "A"   "2*B"
x<-c('a+b','c+d','1 + 2'); lapply(x,ftsplit,'+')
[[1]]
[1] "a" "b"
[[2]]
[1] "c" "d"
[[3]]
[1] "1" "2"
this also works, but mixes up the components:
x<-c('a+b','c+d+1','1 / 2'); ftsplit(x,'+')
[1] "a"	 "b"	 "c"	 "d"	 "1"	 "1 / 2"

a-kramer/SBtabVFGEN documentation built on Nov. 14, 2024, 8:41 p.m.