Learn R Programming

About

quanteda is an R package for managing and analyzing text, created and maintained by Kenneth Benoit and Kohei Watanabe. Its creation was funded by the European Research Council grant ERC-2011-StG 283794-QUANTESS and its continued development is supported by the Quanteda Initiative CIC.

For more details, see https://quanteda.io.

quanteda version 4

The quanteda 4.0 is a major release that improves functionality and performance and further improves function consistency by removing previously deprecated functions. It also includes significant new tokeniser rules that make the default tokeniser smarter than ever, with new Unicode and ICU-compliant rules enabling it to work more consistently with even more languages.

We describe more fully these significant changes in:

The quanteda family of packages

We completed the trend of splitting quanteda into modular packages with the release of v3. The quanteda family of packages includes the following:

  • quanteda: contains all of the core natural language processing and textual data management functions
  • quanteda.textmodels: contains all of the text models and supporting functions, namely the textmodel_*() functions. This was split from the main package with the v2 release
  • quanteda.textstats: statistics for textual data, namely the textstat_*() functions, split with the v3 release
  • quanteda.textplots: plots for textual data, namely the textplot_*() functions, split with the v3 release

We are working on additional package releases, available in the meantime from our GitHub pages:

  • quanteda.sentiment: Functions and lexicons for sentiment analysis using dictionaries
  • quanteda.tidy: Extensions for manipulating document variables in core quanteda objects using your favourite tidyverse functions

and more to come.

How To…

Install (binaries) from CRAN

The normal way from CRAN, using your R GUI or

install.packages("quanteda") 

(New for quanteda v4.0) For Linux users: Because all installations on Linux are compiled, Linux users will first need to install the Intel oneAPI Threading Building Blocks for parallel computing for installation to work.

To install TBB on Linux:

# Fedora, CentOS, RHEL
sudo yum install tbb-devel

# Debian and Ubuntu
sudo apt install libtbb-dev

Compile from source (macOS and Windows)

Because this compiles some C++ and Fortran source code, you will need to have installed the appropriate compilers to build the development version.

You will also need to install TBB:

macOS:

First, you will need to install XCode command line tools.

xcode-select --install

Then install the TBB libraries and the pkg-config utility: (after installing Homebrew):

brew install tbb pkg-config

Finally, you will need to install gfortran.

Windows:

Install RTools, which includes the TBB libraries.

Enable parallelisation

quanteda takes advantage of parallel computing through the TBB (Threading Building Blocks) library to speed up computations. This guide provides step-by-step instructions on how to set up your system for using Quanteda with parallel capabilities on Windows, macOS, and Linux.

Windows:

Download and install RTools from RTools download page.

macOS:

  1. Install XCode Command Line Tools
    • Type the following command in the terminal:

      xcode-select --install
  2. Install Homebrew
    • If Homebrew is not installed, run:

      /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  3. Install TBB and pkg-config
    • After installing Homebrew, run:

      brew install tbb pkg-config
  4. Install gfortran
    • Required for compiling Fortran code, install using Homebrew:

      brew install gcc

Linux:

Install TBB:

  • For Fedora, CentOS, RHEL:

    sudo yum install tbb-devel
  • For Debian and Ubuntu:

    sudo apt install libtbb-dev

More details are provided in the quanteda documentation.

Use quanteda

See the quick start guide to learn how to use quanteda.

Get Help

Cite the package

Benoit, Kenneth, Kohei Watanabe, Haiyan Wang, Paul Nulty, Adam Obeng, Stefan Müller, and Akitaka Matsuo. (2018) “quanteda: An R package for the quantitative analysis of textual data”. Journal of Open Source Software 3(30), 774. https://doi.org/10.21105/joss.00774.

For a BibTeX entry, use the output from citation(package = "quanteda").

Leave Feedback

If you like quanteda, please consider leaving feedback or a testimonial here.

Contribute

Contributions in the form of feedback, comments, code, and bug reports are most welcome. How to contribute:

Copy Link

Version

Install

install.packages('quanteda')

Monthly Downloads

14,299

Version

4.5.0

License

GPL-3

Maintainer

Kenneth Benoit

Last Published

August 4th, 2026

Functions in quanteda (4.5.0)

bootstrap_dfm

Bootstrap a dfm
corpus_trim

Remove sentences based on their token lengths or a pattern match
data-internal

Internal data sets
corpus_chunk

Segment a corpus into chunks of a given size
corpus_group

Combine documents in corpus by a grouping variable
corpus_subset

Extract a subset of a corpus
corpus_segment

Segment texts on a pattern match
char_tolower

Convert the case of character objects
data_dfm_lbgexample

dfm from data in Table 1 of Laver, Benoit, and Garry (2003)
corpus-class

Base method extensions for corpus objects
data_dictionary_LSD2015

Lexicoder Sentiment Dictionary (2015)
dfm2lsa

Convert a dfm to an lsa "textmatrix"
corpus_reshape

Recast the document units of a corpus
data_char_sampletext

A paragraph of text for testing various text-based functions
corpus

Construct a corpus object
dfm-internal

Internal functions for dfm objects
dfm_group

Combine documents in a dfm by a grouping variable
dfm_compress

Recombine a dfm or fcm by combining identical dimension elements
dfm-class

Virtual class "dfm" for a document-feature matrix
corpus_sample

Randomly sample documents from a corpus
dfm_lookup

Apply a dictionary to a dfm
dfm_match

Match the dfm columns with given features
dfm

Create a document-feature matrix
dictionary

Create a dictionary object
data-relocated

Formerly included data objects
data_char_ukimmig2010

Immigration-related sections of 2010 UK party manifestos
dfm_tolower

Convert the case of the features of a dfm and combine
fcm_sort

Sort an fcm in alphabetical order of the features
docfreq

Compute the (weighted) document frequency of a feature
featnames

Get the feature labels from a dfm
dfm_trim

Trim a dfm using frequency threshold-based feature selection
fcm

Create a feature co-occurrence matrix
dfm_subset

Extract a subset of a dfm
escape_regex

Internal function for select_types() to escape regular expressions
dfm_weight

Weight the feature frequencies in a dfm
merge_dictionary_values

Internal function to merge values of duplicated keys
index

Locate a pattern in a tokens object
data_corpus_inaugural

US presidential inaugural address texts
dfm_replace

Replace features in dfm
head.dfm

Return the first or last part of a dfm
flatten_list

Internal function to flatten a nested list
dictionary2-class

dictionary class objects and functions
is.collocations

Check if an object is collocations
dfm_tfidf

Weight a dfm by tf-idf
flatten_dictionary

Flatten a hierarchical dictionary into a list of character vectors
make_meta

Internal functions to create a list of the meta fields
names-quanteda

Special handling for names of quanteda objects
expand

Simpler and faster version of expand.grid() in base package
dfm_sample

Randomly sample documents from a dfm
list2dictionary

Internal function to convert a list to a dictionary
get_object_version

Get the package version that created an object
ndoc

Count the number of documents or features
ntoken

Count the number of tokens or types
fcm-class

Virtual class "fcm" for a feature co-occurrence matrix
object-builders

Object builders
replace_dictionary_values

Internal function to replace dictionary values
is_glob

Check if patterns contains glob wildcard
nest_dictionary

Utility function to generate a nested list
field_system

Shortcut functions to access or assign metadata
matrix2dfm

Converts a Matrix to a dfm
message_error

Return an error message
dfm_sort

Sort a dfm by frequency of one or more margins
message_tokens

Print messages in tokens methods
spacyr-methods

Extensions for and from spacy_parse objects
print.phrases

Print a phrase object
groups

Grouping variable(s) for various functions
search_index

Internal function for select_types to search the index using fastmatch.
resample

Sample a vector
dfm_select

Select features from a dfm or fcm
docnames

Get or set document names
%>%

Pipe operator
remove_empty_keys

Utility function to remove empty keys
matrix2fcm

Converts a Matrix to a fcm
print-methods

Print methods for quanteda core objects
reexports

Objects exported from other packages
kwic

Locate keywords-in-context
sparsity

Compute the sparsity of a document-feature matrix
featfreq

Compute the frequencies of features
inflect

Return inflected forms of words
nsentence

Count the number of sentences
phrase

Declare a pattern to be a sequence of separate patterns
make_docvars

Internal function to make new system-level docvars
tokens_compound

Convert token sequences into compound tokens
msg

Conditionally format messages
docvars

Get or set document-level variables
summary.corpus

Summarize a corpus
tokens_select

Select or remove tokens from a tokens object
quanteda_options

Get or set package options for quanteda
textplots

Plots for textual data
split_values

Internal function for special handling of multi-word dictionary values
quanteda-package

An R package for the quantitative analysis of textual data
tokens_chunk

Segment tokens object by chunks of a given size
tokens_segment

Segment tokens object by patterns
tokens

Construct a tokens object
textmodels

Models for scaling and classification of textual data
lowercase_dictionary_values

Internal function to lowercase dictionary values
serialize_tokens

Function to serialize list-of-character tokens
read_dict_functions

Internal functions to import dictionary files
tokens_trim

Trim tokens using frequency threshold-based feature selection
tokens_tolower

Convert the case of tokens
info_tbb

Get information on TBB library
tokens_annotate

Annotate a tokens object using a dictionary
meta_system

Internal function to get, set or initialize system metadata
tokens_restore

Restore special tokens
tokenize_internal

quanteda tokenizers
pattern2id

Match patterns against token types
texts

Get or assign corpus texts [deprecated]
tokens-class

Base method extensions for tokens objects
tokenize_dictionary

Separate dictionary values using tokenizer
tokens_recompile

Remove redundant or unused tokens IDs
tokens_sample

Randomly sample documents from a tokens object
tokens_replace

Replace tokens in a tokens object
tokenize_dictionary_values

Internal function to tokenize dictionary values
unlist_character

Unlist a list of character vectors safely
types

Get word types from a tokens object
topfeatures

Identify the most frequent features in a dfm
unlist_integer

Unlist a list of integer vectors safely
set_dfm_dimnames<-

Internal functions to set dimnames
textstats

Statistics for textual data
tokens_match

Match the tokens IDs with given types
select_dictionary_levels

Internal function to select dictionary nested levels
tokens_split

Split tokens by a separator pattern
tokenize_custom

Customizable tokenizer
valuetype

Pattern matching using valuetype
format_sparsity

format a sparsity value for printing
wrap

Wrap and print long lines
tokens_ngrams

Create n-grams and skip-grams from tokens
get_docvars

Internal function to extract docvars
tokens_subset

Extract a subset of a tokens
is_regex

Check if a string is a regular expression
is_indexed

Check if a glob pattern is indexed by index_types
object2id

Match quanteda objects against token types
message_dfm

Print messages in dfm methods
pattern

Pattern for feature, token and keyword matching
meta

Get or set object metadata
messages

Message parameter documentation
tokens_wordstem

Stem the terms in an object
message_corpus

Print messages in corpus methods
tokens_xptr

Methods for tokens_xptr objects
reshape_docvars

Internal function to subset or duplicate docvar rows
search_glob

Select types without performing slow regex search
tokens_lookup

Apply a dictionary to a tokens object
tokens_group

Combine documents in a tokens object by a grouping variable
summary_metadata

Functions to add or retrieve corpus summary metadata
as.yaml

Convert quanteda dictionary objects to the YAML format
as.dictionary

Coercion and checking functions for dictionary objects
as.dfm

Coercion and checking functions for dfm objects
as.list.tokens

Coercion, checking, and combining functions for tokens objects
as.fcm

Coercion and checking functions for fcm objects
as.matrix.dfm

Coerce a dfm to a matrix or data.frame
as.character.corpus

Coercion and checking methods for corpus objects
convert

Convert quanteda objects to non-quanteda formats
concat

Return the concatenator character from an object
char_select

Select or remove elements from a character vector
as.data.frame.dfm

Convert a dfm to a data.frame
check_dots

Check arguments passed to other functions via ...
convert-wrappers

Convenience wrappers for dfm convert
apply_if

Modify only documents matching a logical condition
attributes<-

Function extending base::attributes()
check_integer

Validate input vectors
cbind.dfm

Combine dfm objects by Rows or Columns
check_class

Check object class for functions