character-utils {S4Vectors} | R Documentation

## Some utility functions to operate on strings

### Description

Some low-level string utilities to operate on ordinary character vectors. For more advanced string manipulations, see the Biostrings package.

### Usage

    unstrsplit(x, sep="")

    ## more to come...

### Arguments

`x` | A list-like object where each list element is a character vector, or a character vector (identity).
`sep` | A single string containing the separator.

### Details

`unstrsplit(x, sep)` is equivalent to (but much faster than) `sapply(x, paste0, collapse=sep)`. It performs the reverse transformation of `strsplit( , fixed=TRUE)`, that is, if `x` is a character vector with no NAs and `sep` a single string, then `unstrsplit(strsplit(x, split=sep, fixed=TRUE), sep)` is identical to `x`. A notable exception to this though is when `strsplit` finds a match at the end of a string, in which case the last element of the output (which should normally be an empty string) is not returned (see `?strsplit` for the details).

### Value

A character vector with one string per list element in `x`.

### Author(s)

Hervé Pagès

### See Also

- The `strsplit` function in the base package.

### Examples

    x <- list(A=c("abc", "XY"), B=NULL, C=letters[1:4])
    unstrsplit(x)
    unstrsplit(x, sep=",")
    unstrsplit(x, sep=" => ")

    data(islands)
    x <- names(islands)
    y <- strsplit(x, split=" ", fixed=TRUE)
    x2 <- unstrsplit(y, sep=" ")
    stopifnot(identical(x, x2))

    ## But...
    names(x) <- x
    y <- strsplit(x, split="in", fixed=TRUE)
    x2 <- unstrsplit(y, sep="in")
    y[x != x2]
    ## In other words: strsplit() behavior sucks :-/

[Package S4Vectors version 0.18.3 Index]