as_types {mclm}R Documentation

Coerce object to a vector of types

Description

This function coerces an object, such as a character vector, to an object of class types.

Usage

as_types(x, remove_duplicates = TRUE, sort = TRUE, ...)

Arguments

x

Object to coerce

remove_duplicates

Logical. Should duplicates be removed from x prior to coercing to a vector of types.

sort

Logical. Should x be alphabetically sorted prior to coercing to a vector of types; this argument is ignored if remove_duplicates is TRUE, because the result of removing duplicates is always sorted.

...

Additional arguments (not implemented)

Value

An object of the class types, which is based on a character vector. It has additional attributes and methods such as:

An object of class types can be merged with another by means of types_merge(), written to file with write_types() and read from file with write_types().

See Also

types()

Examples


toy_corpus <- "Once upon a time there was a tiny toy corpus.
It consisted of three sentences. And it lived happily ever after."

flist <- freqlist(toy_corpus, re_token_splitter = "\\W+", as_text = TRUE)
print(flist, n = 1000)
(sel_types <- as_types(c("happily", "lived", "once")))
keep_types(flist, sel_types)
tks <- tokenize(toy_corpus, re_token_splitter = "\\W+")
print(tks, n = 1000)
tks[3:12] # idx is relative to selection
head(tks) # idx is relative to selection
tail(tks) # idx is relative to selection

[Package mclm version 0.2.7 Index]