letter {Biostrings}R Documentation

Subsetting a string

Description

Extract a substring from a string by picking up individual letters by their position.

Usage

  letter(x, i)

Arguments

x A character vector, a BString (or derived) object or a BStringViews object.
i An NA-free numeric vector.

Details

Unlike with the substr or substring functions, i must contain valid positions.

Value

A character vector of length 1 when x is a BString (or derived) object.
A character vector of the same length as x when x is a character vector or a BStringViews object.
Note that, because i must contain valid positions, all non-NA elements in the result are guaranted to have exactly length(i) characters.

See Also

subBString, BString-class, BStringViews-class

Examples

  x <- c("abcd", "ABC")
  i <- c(3, 1, 1, 2, 1)

  ## With a character vector
  letter(x[1], 3:1)
  letter(x, 3)
  letter(x, i)
  #letter(x, 4)             # Error!

  ## With a BString object
  letter(BString(x[1]), i)  # character vector
  BString(x[1])[i]          # BString object

  ## With a BStringViews object
  x2 <- BStringViews(x, "BString")
  letter(x2, i)

[Package Biostrings version 2.6.6 Index]