Learn R Programming

corpus (version 0.3.1)

text: Text Vectors

Description

Create or test for objects of type "text".

Usage

as_text(x, ...)
    is_text(x)

Arguments

x
object to be coerced or tested.
further arguments passed to or from other methods.

Value

as.text attempts to coerce its argument to text type; it strips attributes including names.

is.text returns TRUE or FALSE depending on whether its argument is of text type or not.

Details

The text type is a new datatype provided by the corpus package suitable for processing Unicode text. Text vectors behave like character vectors (and can be converted to them with the as.character function). They can be created using the read_ndjson function or by converting another object using the as_text function.

The as_text function first gets the names of the object by calling names(x); then, it converts the object to type "text" and drops all of the object attributes. Finally, the function sets the converted objects names to original object names. This special handling for the names of the object is different from the other R conversion functions (as.numeric, as.character, etc.), which drop the names.

as_text and is_text are generic: you can write methods to handle specific classes of objects. The default behavior is to extract the names from the object using the names function, then call as.character on the object and convert the resulting character vector to a text object.

See Also

read_ndjson.

Examples

Run this code
    as_text("hello, world!")
    as_text(c(a="goodnight", b="moon")) # keeps names

    is_text("hello") # FALSE, "hello" is character, not text

Run the code above in your browser using DataLab