as_types: Coerce object to a vector of types

View source: R/types.R

as_typesR 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:

  • base print(), as_data_frame(), sort() and base::summary() (which returns the number of items and of unique items),

  • tibble::as_tibble(),

  • the n_types() getter and the explore() method,

  • subsetting methods such as keep_types(), keep_pos(), etc. including [] subsetting (see brackets).

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

mclm documentation built on Oct. 3, 2022, 9:07 a.m.