paste2 {BiocGenerics}R Documentation

Concatenate strings (binary form)

Description

paste2() is a simplified version of paste0() that takes only two arguments and follows the same rules as arithmetic operations (+, *, etc...) for recycling and propagation of names, dimensions, and dimnames.

add_prefix() and add_suffix() are simple wrappers around paste2() provided for convenience and code readability.

Usage

paste2(x, y)

add_prefix(x, prefix="")
add_suffix(x, suffix="")

Arguments

x, y, prefix, suffix

Vector- or array-like objects containing strings.

Details

Unlike paste0(), paste2() only takes two arguments: x and y. It's defined as an S4 generic that dispatches on its two arguments and with methods for ordinary vectors and arrays. Bioconductor packages can define methods for other vector-like or array-like objects that contain strings.

paste2() follows the same rules as arithmetic operations (+, *, etc...) for recycling and propagation of names, dimensions, and dimnames:

add_prefix(x, prefix="") and add_suffix(x, suffix="") are convenience wrappers that just do paste2(prefix, x) and paste2(x, suffix), respectively.

Value

If x and y are both vectors, a character vector parallel to the longer vector is returned.

If one of x or y is an array and the other one a vector, an array parallel to the input array is returned.

If x and y are both arrays (in which case they must be conformable), an array parallel to x and y is returned.

See Also

Examples

## ---------------------------------------------------------------------
## The paste2() generic and methods
## ---------------------------------------------------------------------

paste2  # note the dispatch on 'x' and 'y'
showMethods("paste2")

## ---------------------------------------------------------------------
## paste0() vs paste2()
## ---------------------------------------------------------------------

## Propagation of names:
x <- c(A="foo", B="bar")
paste0(x, "XX")  # names are lost
paste2(x, "XX")  # names are propagated
paste2(x, setNames(1:6, letters[1:6]))  # longer argument "wins"

## If 'x' or 'y' has length 0:
paste0(x, character(0))  # unname(x)
paste2(x, character(0))  # character(0)

## Propagation of dimensions and dimnames:
m <- matrix(1:12, ncol=3, dimnames=list(NULL, LETTERS[1:3]))
paste0(m, letters[1:4])  # dimensions and dimnames are lost
paste2(m, letters[1:4])  # dimensions are preserved and dimnames are
                         # propagated

## ---------------------------------------------------------------------
## add_prefix() and add_suffix()
## ---------------------------------------------------------------------

m2 <- add_prefix(m, "ID")  # same as paste2("ID", m)
add_suffix(m2, ".fasta")   # same as paste2(m2, ".fasta")

[Package BiocGenerics version 0.54.0 Index]