tm (version 0.5-10)

tm_filter: Filter and Index Functions on Corpora

Description

Interface to apply filter and index functions to corpora.

Usage

## S3 method for class 'Corpus':
tm_filter(x, \dots, FUN, doclevel = TRUE, useMeta = FALSE)
## S3 method for class 'Corpus':
tm_index(x, \dots, FUN, doclevel = TRUE, useMeta = FALSE)

Arguments

x
A corpus.
...
Arguments to FUN.
FUN
A filter function returning a logical value.
doclevel
Logical. If the document level flag is set FUN is applied to each element of x, otherwise FUN is applied to x itself. If FUN has an attribute doclevel its value will
useMeta
Logical. Should DMetaData be passed over to FUN as argument?

Value

  • tm_filter returns a corpus containing documents where FUN matches, whereas tm_index only returns the corresponding indices.

See Also

sFilter for a filter using a simple statement query language.

Examples

Run this code
data("crude")
# Full-text search
tm_filter(crude, FUN = function(x) any(grep("co[m]?pany", x)))

Run the code above in your browser using DataLab