tm_filter {tm}R Documentation

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, ..., FUN, doclevel = TRUE, useMeta = FALSE)
## S3 method for class 'Corpus'
tm_index(x, ..., 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 be automatically used.

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

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

[Package tm version 0.5-10 Index]