Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

text_sub

Text Subsequences


Description

Extract token subsequences from a set of texts.

Usage

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

Arguments

x

text vector or corpus object.

start

integer vector giving the starting positions of the subsequences, or a two-column integer matrix giving the starting and ending positions.

end

integer vector giving the ending positions of the subsequences; ignored if start is a two-column matrix.

filter

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.

See Also

Examples

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

# entire text
text_sub(x, 1, -1)

# first three elements
text_sub(x, 1, 3)

# last two elements
text_sub(x, -2, -1)

corpus

Text Corpus Analysis

v0.10.2
Apache License (== 2.0) | file LICENSE
Authors
Leslie Huang [cre, ctb], Patrick O. Perry [aut, cph], Finn Årup Nielsen [cph, dtc] (AFINN Sentiment Lexicon), Martin Porter and Richard Boulton [ctb, cph, dtc] (Snowball Stemmer and Stopword Lists), The Regents of the University of California [ctb, cph] (Strtod Library Procedure), Carlo Strapparava and Alessandro Valitutti [cph, dtc] (WordNet-Affect Lexicon), Unicode, Inc. [cph, dtc] (Unicode Character Database)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.