knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "##",
  fig.path = "man/images/"
)
library("badger")

quanteda.tidy

CRAN_Status_Badge r badge_devel("quanteda/quanteda.tidy", "royalblue") Lifecycle: experimental R build status Coverage Status

About

quanteda.tidy extends the quanteda package with functionality from the "tidyverse", especially dplyr.
Note that this is not the same as tidytext, which stretches tokens into data.frames. Instead, tidy functions operate only on document variables, but extends these functions (from dplyr) to work on quanteda objects as if they were tibbles or data.frames.

Installation

You can install quanteda.tidy from GitHub with:

devtools::install_github("quanteda/quanteda.tidy")

Examples

Adding a document variable for full president name:

library("quanteda.tidy", warn.conflicts = FALSE)

data_corpus_inaugural %>%
  transmute(fullname = paste(FirstName, President, sep = ", ")) %>%
  summary(n = 5)

data_corpus_inaugural %>%
  mutate(fullname = paste(FirstName, President, sep = ", ")) %>%
  summary(n = 5)

Filtering documents based on years:

data_corpus_inaugural %>%
  filter(President == "Roosevelt") %>%
  summary()

Renaming document variables:

data_corpus_inaugural %>%
  rename(LastName = President) %>%
  select(FirstName, LastName) %>%
  summary(n = 5)

Glimpse (from tibble):

glimpse(data_corpus_inaugural)

Slice operations:

slice(data_corpus_inaugural, 1:3)

slice_head(data_corpus_inaugural, prop = .10)
slice_tail(data_corpus_inaugural, n = 3)

set.seed(42)
slice_sample(data_corpus_inaugural, prop = .50)


quanteda/quanteda.tidy documentation built on April 11, 2021, 3:44 p.m.