Learn R Programming

⚠️There's a newer version (4.3.1) of this package.Take me there.

About

An R package for managing and analyzing text, created by Kenneth Benoit. Supported by the European Research Council grant ERC-2011-StG 283794-QUANTESS.

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

quanteda version 3

The quanteda 3.0 major release improves functionality, completes the modularisation of the package begun in v2.0, further improves function consistency by removing previously deprecated functions, and enhances workflow stability and consistency by deprecating some shortcut steps built into some functions.

See https://github.com/quanteda/quanteda/blob/master/NEWS.md#quanteda-30 for a full list of the changes.

The quanteda family of packages

As of v3.0, we have continued our trend of splitting quanteda into modular packages. These are now 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…

How to Install

The normal way from CRAN, using your R GUI or

install.packages("quanteda") 

Or for the latest development version:

# devtools package required to install quanteda from Github 
remotes::install_github("quanteda/quanteda") 

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

How to Use

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

How to Get Help

How to Cite

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").

How to Leave Feedback

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

How to 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

18,936

Version

3.3.0

License

GPL-3

Maintainer

Kenneth Benoit

Last Published

April 7th, 2023

Functions in quanteda (3.3.0)

check_dots

Check arguments passed to other functions via ...
cbind.dfm

Combine dfm objects by Rows or Columns
convert

Convert quanteda objects to non-quanteda formats
char_tolower

Convert the case of character objects
corpus

Construct a corpus object
convert-wrappers

Convenience wrappers for dfm convert
check_class

Check object class for functions
corpus-class

Base method extensions for corpus objects
check_integer

Validate input vectors
char_select

Select or remove elements from a character vector
corpus_sample

Randomly sample documents from a corpus
corpus_subset

Extract a subset of a corpus
corpus_segment

Segment texts on a pattern match
data_char_sampletext

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

Recast the document units of a corpus
corpus_group

Combine documents in corpus by a grouping variable
data_corpus_inaugural

US presidential inaugural address texts
data_dfm_lbgexample

dfm from data in Table 1 of Laver, Benoit, and Garry (2003)
dfm2lsa

Convert a dfm to an lsa "textmatrix"
dfm_group

Combine documents in a dfm by a grouping variable
corpus_trim

Remove sentences based on their token lengths or a pattern match
data_char_ukimmig2010

Immigration-related sections of 2010 UK party manifestos
dfm_lookup

Apply a dictionary to a dfm
dfm

Create a document-feature matrix
dfm_compress

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

Internal functions for dfm objects
data-internal

Internal data sets
data-relocated

Formerly included data objects
dfm_sample

Randomly sample documents from a dfm
dfm_tolower

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

Select features from a dfm or fcm
dfm_tfidf

Weight a dfm by tf-idf
data_dictionary_LSD2015

Lexicoder Sentiment Dictionary (2015)
dfm_replace

Replace features in dfm
dfm_match

Match the feature set of a dfm to given feature names
dictionary2-class

dictionary class objects and functions
expand

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

Get or set document-level variables
dfm_trim

Trim a dfm using frequency threshold-based feature selection
dfm_weight

Weight the feature frequencies in a dfm
dfm_subset

Extract a subset of a dfm
docfreq

Compute the (weighted) document frequency of a feature
dfm_sort

Sort a dfm by frequency of one or more margins
fcm_sort

Sort an fcm in alphabetical order of the features
fcm

Create a feature co-occurrence matrix
featfreq

Compute the frequencies of features
featnames

Get the feature labels from a dfm
dfm-class

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

Create a dictionary
escape_regex

Internal function for select_types() to escape regular expressions
index

Locate a pattern in a tokens object
get_docvars

Internal function to extract docvars
get_object_version

Get the package version that created an object
make_meta

Internal functions to create a list of the meta fields
make_docvars

Internal function to make new system-level docvars
groups

Grouping variable(s) for various functions
fcm-class

Virtual class "fcm" for a feature co-occurrence matrix
docnames

Get or set document names
format_sparsity

format a sparsity value for printing
flatten_list

Internal function to flatten a nested list
is.collocations

Check if an object is collocations
meta

Get or set object metadata
meta_system

Internal function to get, set or initialize system metadata
msg

Conditionally format messages
ntoken

Count the number of tokens or types
names-quanteda

Special handling for names of quanteda objects
nsentence

Count the number of sentences
kwic

Locate keywords-in-context
is_regex

Check if a string is a regular expression
%>%

Pipe operator
pattern

Pattern for feature, token and keyword matching
merge_dictionary_values

Internal function to merge values of duplicated keys
pattern2id

Match patterns against token types
phrase

Declare a pattern to be a sequence of separate patterns
head.dfm

Return the first or last part of a dfm
field_system

Shortcut functions to access or assign metadata
matrix2dfm

Converts a Matrix to a dfm
reexports

Objects exported from other packages
nest_dictionary

Utility function to generate a nested list
replace_dictionary_values

Internal function to replace dictionary values
list2dictionary

Internal function to convert a list to a dictionary
flatten_dictionary

Flatten a hierarchical dictionary into a list of character vectors
remove_empty_keys

Utility function to remove empty keys
object2id

Match quanteda objects against token types
summary.corpus

Summarize a corpus
summary_metadata

Functions to add or retrieve corpus summary metadata
lowercase_dictionary_values

Internal function to lowercase dictionary values
object-builders

Object builders
tokens_group

Combine documents in a tokens object by a grouping variable
reshape_docvars

Internal function to subset or duplicate docvar rows
message_error

Return an error message
tokens_lookup

Apply a dictionary to a tokens object
textmodels

Models for scaling and classification of textual data
texts

Get or assign corpus texts [deprecated]
search_glob

Select types without performing slow regex search
set_dfm_dimnames<-

Internal functions to set dimnames
is_glob

Check if patterns contains glob wildcard
spacyr-methods

Extensions for and from spacy_parse objects
resample

Sample a vector
textstats

Statistics for textual data
split_values

Internal function for special handling of multi-word dictionary values
sparsity

Compute the sparsity of a document-feature matrix
tokens_replace

Replace tokens in a tokens object
textplots

Plots for textual data
ndoc

Count the number of documents or features
search_index

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

Check if a glob pattern is indexed by index_types
tokens_restore

Restore special tokens
topfeatures

Identify the most frequent features in a dfm
tokens_sample

Randomly sample documents from a tokens object
tokens_segment

Segment tokens object by patterns
matrix2fcm

Converts a Matrix to a fcm
tokens-class

Base method extensions for tokens objects
tokens_select

Select or remove tokens from a tokens object
tokens_wordstem

Stem the terms in an object
tokens_subset

Extract a subset of a tokens
tokens

Construct a tokens object
quanteda-package

An R package for the quantitative analysis of textual data
quanteda_options

Get or set package options for quanteda
tokens_split

Split tokens by a separator pattern
tokens_chunk

Segment tokens object by chunks of a given size
tokens_compound

Convert token sequences into compound tokens
serialize_tokens

Function to serialize list-of-character tokens
tokens_recompile

recompile a serialized tokens object
print-methods

Print methods for quanteda core objects
print.phrases

Print a phrase object
tokenize_internal

quanteda tokenizers
read_dict_functions

Internal functions to import dictionary files
types

Get word types from a tokens object
unlist_character

Unlist a list of character vectors safely
tokens_tolower

Convert the case of tokens
unlist_integer

Unlist a list of integer vectors safely
valuetype

Pattern matching using valuetype
readtext-methods

Extensions for readtext objects
tokenize_custom

Customizable tokenizer
tokens_ngrams

Create n-grams and skip-grams from tokens
as.data.frame.dfm

Convert a dfm to a data.frame
as.list.tokens

Coercion, checking, and combining functions for tokens objects
as.character.corpus

Coercion and checking methods for corpus objects
as.yaml

Convert quanteda dictionary objects to the YAML format
as.fcm

Coercion and checking functions for fcm objects
as.dfm

Coercion and checking functions for dfm objects
as.dictionary

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

Coerce a dfm to a matrix or data.frame
attributes<-

Function extending base::attributes()
bootstrap_dfm

Bootstrap a dfm