R: Recast the document units of a corpus

corpus_reshape {quanteda} | R Documentation

## Recast the document units of a corpus

### Description

For a corpus, reshape (or recast) the documents to a different level of aggregation. Units of aggregation can be defined as documents, paragraphs, or sentences. Because the corpus object records its current "units" status, it is possible to move from recast units back to original units, for example from documents, to sentences, and then back to documents (possibly after modifying the sentences).

### Usage

    corpus_reshape(
      x,
      to = c("sentences", "paragraphs", "documents"),
      use_docvars = TRUE,
      ...
    )

### Arguments

`x` | corpus whose document units will be reshaped
`to` | new document units in which the corpus will be recast
`use_docvars` | if `TRUE`, repeat the docvar values for each segmented text; if `FALSE`, drop the docvars in the segmented corpus. Dropping the docvars might be useful in order to conserve space or if these are not desired for the segmented corpus.
`...` | additional arguments passed to `tokens()`, since the syntactic segmenter uses this function)

### Value

A corpus object with the documents defined as the new units, including document-level meta-data identifying the original documents.

### Examples

    # simple example
    corp1 <- corpus(c(textone = "This is a sentence.  Another sentence.  Yet another.",
                     textwo = "Premiere phrase.  Deuxieme phrase."),
                     docvars = data.frame(country=c("UK", "USA"), year=c(1990, 2000)))
    summary(corp1)
    summary(corpus_reshape(corp1, to = "sentences"))

    # example with inaugural corpus speeches
    (corp2 <- corpus_subset(data_corpus_inaugural, Year>2004))
    corp2para <- corpus_reshape(corp2, to = "paragraphs")
    corp2para
    summary(corp2para, 50, showmeta = TRUE)
    ## Note that Bush 2005 is recorded as a single paragraph because that text
    ## used a single \n to mark the end of a paragraph.

[Package quanteda version 3.0.0 Index]