Extract token subsequences from a set of texts.

text_sub(x, start = 1L, end = -1L, filter = NULL, ...)

## Arguments

x text vector or corpus object. integer vector giving the starting positions of the subsequences, or a two-column integer matrix giving the starting and ending positions. integer vector giving the ending positions of the subsequences; ignored if start is a two-column matrix. if non-NULL, a text filter to to use instead of the default text filter for x. additional properties to set on the text filter.

## Details

text_sub extracts token subsequences from a set of texts. The start and end arguments specifying the positions of the subsequences within the parent texts, as an inclusive range. Negative indices are interpreted as counting from the end of the text, with -1L referring to the last element.

## Value

A text vector with the same length and names as x, with the desired subsequences.

text_tokens, text_ntoken.

## Examples

x <- as_corpus_text(c("A man, a plan.", "A \"canal\"?", "Panama!"),
drop_punct = TRUE)

# entire text
text_sub(x, 1, -1)#> [1] "A man, a plan." "A \"canal\"?"   "Panama!"
# first three elements
text_sub(x, 1, 3)#> [1] "A man, a "    "A \"canal\"?" "Panama!"
# last two elements
text_sub(x, -2, -1)#> [1] "a plan."      "A \"canal\"?" "Panama!"